Java Code Examples for android.app.PendingIntent#getCreatorPackage()

The following examples show how to use android.app.PendingIntent#getCreatorPackage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiCompatibilityUtils.java    From cronet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see android.app.PendingIntent#getCreatorPackage()
 */
@SuppressWarnings("deprecation")
public static String getCreatorPackage(PendingIntent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return intent.getCreatorPackage();
    } else {
        return intent.getTargetPackage();
    }
}
 
Example 2
Source File: ApiDispatcher.java    From island with Apache License 2.0 5 votes vote down vote up
/**
 * Verify the qualification of this API invocation, mainly the permission of API caller.
 *
 * @param pkg the package name of API caller, if known.
 * @param uid the UID of API caller, not used if caller_pkg is null.
 * @return null if verified, or error message for debugging purpose (NOT part of the API protocol).
 */
static String verifyCaller(final Context context, final Intent intent, @Nullable String pkg, int uid) {
	if (pkg == null) {
		final PendingIntent id = intent.getParcelableExtra(Api.latest.EXTRA_CALLER_ID);
		if (id == null) return "Missing required PendingIntent extra: " + Api.latest.EXTRA_CALLER_ID;
		pkg = id.getCreatorPackage();
		uid = id.getCreatorUid();
		if (pkg == null) return "No creator information in " + id;
	}
	if (Users.isSameApp(uid, Process.myUid())) return null;		// From myself (possibly in other user).
	// This log should generally be placed in the caller site, do it after same app check to skip this for internal API caller with component set.
	if (intent.getPackage() == null && intent.getComponent() != null)
		Log.w(TAG, "Never use implicit intent or explicit intent with component name for API request, use Intent.setPackage() instead.");

	Log.d(TAG, "API invoked by " + pkg);
	if (SDK_INT >= M) {
		final int permission_result = context.checkPermission(Api.latest.PERMISSION_FREEZE_PACKAGE, 0, uid);
		if (permission_result == PackageManager.PERMISSION_GRANTED) return null;
	}

	// Fallback verification for API v1 clients.
	final Integer value = sVerifiedCallers.get(pkg);
	if (value == null) return "Unauthorized client: " + pkg;
	final int signature_hash = value;
	if (signature_hash == 0) return null;	// 0 means already verified (cached)

	// Legacy verification is not supported inside Island without INTERACT_ACROSS_USERS on Android P+, due to MATCH_ANY_USER being restricted.
	try { @SuppressWarnings("deprecation") @SuppressLint({"PackageManagerGetSignatures", "WrongConstant"})
		final PackageInfo pkg_info = context.getPackageManager().getPackageInfo(pkg, GET_SIGNATURES
			| (SDK_INT < P || Permissions.has(context, INTERACT_ACROSS_USERS) ? Hacks.MATCH_ANY_USER_AND_UNINSTALLED : GET_UNINSTALLED_PACKAGES));
		return verifySignature(pkg, signature_hash, pkg_info);
	} catch (final PackageManager.NameNotFoundException e) { return "Permission denied or client package not found: " + pkg; }
}
 
Example 3
Source File: BrowserActionsIntent.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
/**
 * Get the package name of the creator application.
 * <p>
 * <strong> Note:</strong> This is self-reported and could be untrusted. Intent sender can
 * modify it to return the package name from a different application.
 *
 * @param intent The {@link BrowserActionsIntent}.
 * @return The creator package name.
 */
@SuppressWarnings("deprecation")
public static String getUntrustedCreatorPackageName(Intent intent) {
    PendingIntent pendingIntent = intent.getParcelableExtra(BrowserActionsIntent.EXTRA_APP_ID);
    if (pendingIntent != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return pendingIntent.getCreatorPackage();
        } else {
            return pendingIntent.getTargetPackage();
        }
    }
    return null;
}
 
Example 4
Source File: MediaProviderDelegate.java    From Noyze with Apache License 2.0 5 votes vote down vote up
protected void updatePackage() {
    // This is an optional parameter obtained via Reflection, if possible.
    // Useful for obtaining information such as the app's icon and using it in the volume_3 panel.
    if (!IS_V18 || null == remoteMetadataProvider) return;
    LOGI(TAG, "updatePackage()");
    PendingIntent intent = remoteMetadataProvider.getCurrentClientPendingIntent();
    if (null == intent) return;
    playbackInfo.mRemotePackageName = intent.getCreatorPackage();
    if (null != metadata)
        metadata.setRemotePackage(playbackInfo.mRemotePackageName);
}
 
Example 5
Source File: ApiCompatibilityUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @see android.app.PendingIntent#getCreatorPackage()
 */
@SuppressWarnings("deprecation")
public static String getCreatorPackage(PendingIntent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return intent.getCreatorPackage();
    } else {
        return intent.getTargetPackage();
    }
}
 
Example 6
Source File: BrowserActionsIntent.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Get the package name of the creator application.
 * @param intent The {@link BrowserActionsIntent}.
 * @return The creator package name.
 */
@SuppressWarnings("deprecation")
public static String getCreatorPackageName(Intent intent) {
    PendingIntent pendingIntent = intent.getParcelableExtra(BrowserActionsIntent.EXTRA_APP_ID);
    if (pendingIntent != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return pendingIntent.getCreatorPackage();
        } else {
            return pendingIntent.getTargetPackage();
        }
    }
    return null;
}
 
Example 7
Source File: MediaProviderDelegate.java    From Noyze with Apache License 2.0 5 votes vote down vote up
protected void updatePackage() {
    // This is an optional parameter obtained via Reflection, if possible.
    // Useful for obtaining information such as the app's icon and using it in the volume_3 panel.
    if (!IS_V18 || null == remoteMetadataProvider) return;
    LOGI(TAG, "updatePackage()");
    PendingIntent intent = remoteMetadataProvider.getCurrentClientPendingIntent();
    if (null == intent) return;
    playbackInfo.mRemotePackageName = intent.getCreatorPackage();
    if (null != metadata)
        metadata.setRemotePackage(playbackInfo.mRemotePackageName);
}
 
Example 8
Source File: PackageUtils.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static String packageFromPendingIntent(PendingIntent pi) {
    if (pi == null) return null;
    if (SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return pi.getTargetPackage();
    } else {
        return pi.getCreatorPackage();
    }
}
 
Example 9
Source File: AlarmManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private final BroadcastStats getStatsLocked(PendingIntent pi) {
    String pkg = pi.getCreatorPackage();
    int uid = pi.getCreatorUid();
    return getStatsLocked(uid, pkg);
}
 
Example 10
Source File: NextAlarmClockBroadcastReceiver.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    //PPApplication.logE("##### NextAlarmClockBroadcastReceiver.onReceive", "xxx");

    //CallsCounter.logCounter(context, "NextAlarmClockBroadcastReceiver.onReceive", "NextAlarmClockBroadcastReceiver_onReceive");

    if (intent == null)
        return;

    //if (!PPApplication.getApplicationStarted(context.getApplicationContext(), true))
    //    return;

    //if (android.os.Build.VERSION.SDK_INT >= 21) {
        String action = intent.getAction();
        if ((action != null) && action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
            AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            if (alarmManager != null) {
                AlarmManager.AlarmClockInfo alarmClockInfo = alarmManager.getNextAlarmClock();
                if (alarmClockInfo != null) {
                    long _time = alarmClockInfo.getTriggerTime();
                    /*if (PPApplication.logEnabled()) {
                        SimpleDateFormat sdf = new SimpleDateFormat("EE d.MM.yyyy HH:mm:ss:S");
                        String result = sdf.format(_time);
                        PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "_time=" + result);
                    }*/

                    PendingIntent infoPendingIntent = alarmClockInfo.getShowIntent();
                    // infoPendingIntent == null - Xiaomi Clock :-/
                    // infoPendingIntent == null - LG Clock :-/
                    // infoPendingIntent == null - Huawei Clock :-/

                    if (infoPendingIntent != null) {
                        String packageName = infoPendingIntent.getCreatorPackage();
                        //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "packageName=" + packageName);
                        if (packageName != null) {
                            if (!packageName.equals(context.getPackageName())) {
                                //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "packageName=" + packageName);

                                // com.google.android.deskclock - Google Clock
                                // com.sec.android.app.clockpackage - Samsung Clock
                                // com.sonyericsson.organizer - Sony Clock
                                // com.amdroidalarmclock.amdroid - AMdroid
                                // com.alarmclock.xtreme.free - Alarm Clock XTreme free
                                // com.alarmclock.xtreme - Alarm Clock XTreme
                                // droom.sleepIfUCan - Alarmy (Sleep if u can)
                                // com.funanduseful.earlybirdalarm - Early Bird Alarm Clock
                                // com.apalon.alarmclock.smart - Good Morning Alarm Clock
                                // com.kog.alarmclock - I Can't Wake Up! Alarm Clock
                                // com.urbandroid.sleep - Sleep as Android
                                // ch.bitspin.timely - Timely
                                // com.angrydoughnuts.android.alarmclock - Alarm Klock

                                /*if (packageName.equals("com.google.android.deskclock") ||
                                    packageName.equals("com.sec.android.app.clockpackage") ||
                                    packageName.equals("com.sonyericsson.organizer") ||
                                    packageName.equals("com.amdroidalarmclock.amdroid") ||
                                    packageName.equals("com.alarmclock.xtreme") ||
                                    packageName.equals("com.alarmclock.xtreme.free") ||
                                    packageName.equals("droom.sleepIfUCan") ||
                                    packageName.equals("com.funanduseful.earlybirdalarm") ||
                                    packageName.equals("com.apalon.alarmclock.smart") ||
                                    packageName.equals("com.kog.alarmclock") ||
                                    packageName.equals("com.urbandroid.sleep") ||
                                    packageName.equals("ch.bitspin.timely") ||
                                    packageName.equals("com.angrydoughnuts.android.alarmclock"))*/

                                    setAlarm(_time, packageName, alarmManager, context);
                            }
                        } /*else {
                            //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "packageName == null");
                            setAlarm(_time, "", alarmManager, context);
                        }*/
                    } /*else {
                        //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "infoPendingIntent == null");
                        setAlarm(_time, "", alarmManager, context);
                    }*/
                }
                //else {
                    //PPApplication.logE("NextAlarmClockBroadcastReceiver.onReceive", "alarmClockInfo == null");
                    //removeAlarm(alarmManager, context);
                //}
            }
        }
    //}
}