-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
387 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.kooritea.fcmfix; | ||
|
||
import android.content.ContentProvider; | ||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.content.UriMatcher; | ||
import android.database.Cursor; | ||
import android.database.MatrixCursor; | ||
import android.net.Uri; | ||
import android.util.Log; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class XposedProvider extends ContentProvider { | ||
|
||
private static UriMatcher uriMatcher; | ||
|
||
static | ||
{ | ||
uriMatcher=new UriMatcher(UriMatcher.NO_MATCH); | ||
uriMatcher.addURI("com.kooritea.fcmfix.provider","config",0); | ||
} | ||
|
||
@Override | ||
public boolean onCreate() { | ||
return false; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getType(@NonNull Uri uri) { | ||
switch (uriMatcher.match(uri)) | ||
{ | ||
default: | ||
break; | ||
} | ||
return null; | ||
} | ||
|
||
|
||
@Nullable | ||
@Override | ||
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { | ||
//这里填写查询逻辑 | ||
SharedPreferences sharedPreferences = getContext().getSharedPreferences("config", Context.MODE_PRIVATE); | ||
String[] COLUMN_NAME = { "key", "value" }; | ||
MatrixCursor data = new MatrixCursor(COLUMN_NAME); | ||
switch (selection){ | ||
case "heartbeatInterval": | ||
data.addRow(new Object[]{"heartbeatInterval",sharedPreferences.getLong("heartbeatInterval",117000L)}); | ||
break; | ||
case "allowList": | ||
for(String item : sharedPreferences.getStringSet("allowList",new HashSet<String>())){ | ||
data.addRow(new Object[]{"allowList",item}); | ||
} | ||
break; | ||
} | ||
return data; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) { | ||
//这里填写插入逻辑 | ||
return null; | ||
} | ||
|
||
@Override | ||
public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) { | ||
//这里填写更新逻辑 | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) { | ||
//这里填写删除逻辑 | ||
return 0; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
app/src/main/java/com/kooritea/fcmfix/util/ContentProviderHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.kooritea.fcmfix.util; | ||
|
||
import android.content.ContentResolver; | ||
import android.content.Context; | ||
import android.database.ContentObserver; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class ContentProviderHelper { | ||
|
||
public ContentResolver contentResolver; | ||
private Uri uri; | ||
private ArrayList<ContentObserver> contentObservers = new ArrayList<>(); | ||
public Boolean useDefaultValue = false; | ||
|
||
public ContentProviderHelper(Context context, String uri){ | ||
contentResolver = context.getContentResolver(); | ||
this.uri = Uri.parse(uri); | ||
} | ||
public ContentProviderHelper(){ | ||
useDefaultValue = true; | ||
} | ||
|
||
public Long getLong(String selection,Long defaultValue){ | ||
if(useDefaultValue){ | ||
return defaultValue; | ||
} | ||
Cursor cursor = contentResolver.query(uri, null, selection, null,null); | ||
if(cursor == null){ | ||
return defaultValue; | ||
} | ||
cursor.getCount(); | ||
while(cursor.moveToNext()) { | ||
if(selection.equals(cursor.getString(cursor.getColumnIndex("key")))){ | ||
cursor.close(); | ||
return cursor.getLong(cursor.getColumnIndex("value")); | ||
} | ||
} | ||
cursor.close(); | ||
return defaultValue; | ||
} | ||
public String getString(String selection,String defaultValue){ | ||
if(useDefaultValue){ | ||
return defaultValue; | ||
} | ||
Cursor cursor =contentResolver.query(uri, null, selection, null,null); | ||
if(cursor == null){ | ||
return defaultValue; | ||
} | ||
cursor.getCount(); | ||
while(cursor.moveToNext()) { | ||
if(selection.equals(cursor.getString(cursor.getColumnIndex("key")))){ | ||
cursor.close(); | ||
return cursor.getString(cursor.getColumnIndex("value")); | ||
} | ||
} | ||
cursor.close(); | ||
return defaultValue; | ||
} | ||
public Set<String> getStringSet(String selection){ | ||
if(useDefaultValue){ | ||
return new HashSet<String>(); | ||
} | ||
Cursor cursor = contentResolver.query(uri, null, selection, null,null); | ||
if(cursor == null){ | ||
return new HashSet<String>(); | ||
} | ||
cursor.getCount(); | ||
Set<String> result = new HashSet<String>(); | ||
while(cursor.moveToNext()) { | ||
if(selection.equals(cursor.getString(cursor.getColumnIndex("key")))){ | ||
result.add(cursor.getString(cursor.getColumnIndex("value"))); | ||
} | ||
} | ||
cursor.close(); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.