Skip to content

Instantly share code, notes, and snippets.

@frmz
Last active April 18, 2024 02:54
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save frmz/669eeca0b20b943b7091b9078eb3247e to your computer and use it in GitHub Desktop.
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
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");
}
}
@BennyKok
Copy link

I am not sure what had happen, but the delete method was never called, I have sat klwp as wallpaper, and the 5 secs delay toast still come out. Here is my manifest.

       <provider
        android:authorities="com.bennyv4.fivesecdelaycp"
        android:grantUriPermissions="true"
        android:exported="true"
        android:enabled="true"
        android:name=".util.FiveSecsDelayContentProvider"/>

@frmz
Copy link
Author

frmz commented Sep 13, 2016

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

@BennyKok
Copy link

ok, I got it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment