Last active
June 29, 2024 08:48
-
-
Save frmz/669eeca0b20b943b7091b9078eb3247e to your computer and use it in GitHub Desktop.
Example content provider to fix on launcher side the "5 secs delay" security restriction Android has on the Home Button
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
import android.content.ContentProvider; | |
public class Kustom5SecsProvider extends ContentProvider { | |
/** | |
* Path used by Kustom to ask a 5 secs delay reset | |
*/ | |
private final static String PATH_RESET_5SEC_DELAY = "reset5secs"; | |
@Override | |
public boolean onCreate() { | |
return true; | |
} | |
@Nullable | |
@Override | |
public Cursor query(@NonNull Uri uri, | |
String[] projection, | |
String selection, | |
String[] selectionArgs, | |
String sortOrder) { | |
throw new UnsupportedOperationException("Unsupported"); | |
} | |
@Nullable | |
@Override | |
public String getType(@NonNull Uri uri) { | |
// Not supported | |
return null; | |
} | |
@Nullable | |
@Override | |
public Uri insert(@NonNull Uri uri, ContentValues values) { | |
// Not supported | |
throw new UnsupportedOperationException("Unsupported"); | |
} | |
@Override | |
public int delete(@NonNull Uri uri, | |
String selection, | |
String[] selectionArgs) { | |
if(PATH_RESET_5SEC_DELAY.equals(uri.getLastPathSegment()) { | |
/** | |
* Lets ensure this gets executed only by Kustom | |
*/ | |
checkCallingPackage(); | |
/** | |
* This assumes you have a transparent activity that will just call finish() during its onCreate method | |
* Activity in this case also provides a static method for starting itself | |
*/ | |
AutoFinishTransparentActivity.start(getContext()); | |
return 1; | |
} | |
return 0; | |
} | |
@Override | |
public int update(@NonNull Uri uri, | |
ContentValues values, | |
String selection, | |
String[] selectionArgs) { | |
// Not supported | |
throw new UnsupportedOperationException("Unsupported"); | |
} | |
/** | |
* Will check weather or not calling pkg is authorized to talk with this provider | |
* | |
* @throws SecurityException | |
*/ | |
private void checkCallingPackage() throws SecurityException { | |
String callingPkg = getCallingPackage(); | |
if ("org.kustom.wallpaper".equals(callingPkg)) return; | |
if ("org.kustom.widget".equals(callingPkg)) return; | |
if ("org.kustom.lockscreen".equals(callingPkg)) return; | |
throw new SecurityException("Unauthorized"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah, Kustom needs to know that your launcher supports this feature, i need to hardcode it in the app, so if you added the support then open a ticket at help@kustom.rocks mentioning launcher pkg name so i can add it on next release