Search in sources :

Example 46 with INotificationManager

use of android.app.INotificationManager in project android_frameworks_base by crdroidandroid.

the class ConditionProviders method onPackagesChanged.

@Override
public void onPackagesChanged(boolean removingPackage, String[] pkgList) {
    if (removingPackage) {
        INotificationManager inm = NotificationManager.getService();
        if (pkgList != null && (pkgList.length > 0)) {
            for (String pkgName : pkgList) {
                try {
                    inm.removeAutomaticZenRules(pkgName);
                    inm.setNotificationPolicyAccessGranted(pkgName, false);
                } catch (Exception e) {
                    Slog.e(TAG, "Failed to clean up rules for " + pkgName, e);
                }
            }
        }
    }
    super.onPackagesChanged(removingPackage, pkgList);
}
Also used : INotificationManager(android.app.INotificationManager) RemoteException(android.os.RemoteException)

Example 47 with INotificationManager

use of android.app.INotificationManager in project android_frameworks_base by crdroidandroid.

the class NotificationBackupHelper method applyRestoredPayload.

@Override
protected void applyRestoredPayload(String key, byte[] payload) {
    if (DEBUG) {
        Slog.v(TAG, "Got restore of " + key);
    }
    if (KEY_NOTIFICATIONS.equals(key)) {
        try {
            INotificationManager nm = INotificationManager.Stub.asInterface(ServiceManager.getService("notification"));
            // TODO: http://b/22388012
            nm.applyRestore(payload, UserHandle.USER_SYSTEM);
        } catch (Exception e) {
            Slog.e(TAG, "Couldn't communicate with notification manager");
        }
    }
}
Also used : INotificationManager(android.app.INotificationManager)

Example 48 with INotificationManager

use of android.app.INotificationManager in project platform_frameworks_base by android.

the class ActivityManagerService method clearApplicationUserData.

@Override
public boolean clearApplicationUserData(final String packageName, final IPackageDataObserver observer, int userId) {
    enforceNotIsolatedCaller("clearApplicationUserData");
    int uid = Binder.getCallingUid();
    int pid = Binder.getCallingPid();
    userId = mUserController.handleIncomingUser(pid, uid, userId, false, ALLOW_FULL_ONLY, "clearApplicationUserData", null);
    long callingId = Binder.clearCallingIdentity();
    try {
        IPackageManager pm = AppGlobals.getPackageManager();
        int pkgUid = -1;
        synchronized (this) {
            if (getPackageManagerInternalLocked().isPackageDataProtected(userId, packageName)) {
                throw new SecurityException("Cannot clear data for a protected package: " + packageName);
            }
            try {
                pkgUid = pm.getPackageUid(packageName, MATCH_UNINSTALLED_PACKAGES, userId);
            } catch (RemoteException e) {
            }
            if (pkgUid == -1) {
                Slog.w(TAG, "Invalid packageName: " + packageName);
                if (observer != null) {
                    try {
                        observer.onRemoveCompleted(packageName, false);
                    } catch (RemoteException e) {
                        Slog.i(TAG, "Observer no longer exists.");
                    }
                }
                return false;
            }
            if (uid == pkgUid || checkComponentPermission(android.Manifest.permission.CLEAR_APP_USER_DATA, pid, uid, -1, true) == PackageManager.PERMISSION_GRANTED) {
                forceStopPackageLocked(packageName, pkgUid, "clear data");
            } else {
                throw new SecurityException("PID " + pid + " does not have permission " + android.Manifest.permission.CLEAR_APP_USER_DATA + " to clear data" + " of package " + packageName);
            }
            // Remove all tasks match the cleared application package and user
            for (int i = mRecentTasks.size() - 1; i >= 0; i--) {
                final TaskRecord tr = mRecentTasks.get(i);
                final String taskPackageName = tr.getBaseIntent().getComponent().getPackageName();
                if (tr.userId != userId)
                    continue;
                if (!taskPackageName.equals(packageName))
                    continue;
                removeTaskByIdLocked(tr.taskId, false, REMOVE_FROM_RECENTS);
            }
        }
        final int pkgUidF = pkgUid;
        final int userIdF = userId;
        final IPackageDataObserver localObserver = new IPackageDataObserver.Stub() {

            @Override
            public void onRemoveCompleted(String packageName, boolean succeeded) throws RemoteException {
                synchronized (ActivityManagerService.this) {
                    finishForceStopPackageLocked(packageName, pkgUidF);
                }
                final Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, Uri.fromParts("package", packageName, null));
                intent.putExtra(Intent.EXTRA_UID, pkgUidF);
                intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(pkgUidF));
                broadcastIntentInPackage("android", Process.SYSTEM_UID, intent, null, null, 0, null, null, null, null, false, false, userIdF);
                if (observer != null) {
                    observer.onRemoveCompleted(packageName, succeeded);
                }
            }
        };
        try {
            // Clear application user data
            pm.clearApplicationUserData(packageName, localObserver, userId);
            synchronized (this) {
                // Remove all permissions granted from/to this package
                removeUriPermissionsForPackageLocked(packageName, userId, true);
            }
            // Remove all zen rules created by this package; revoke it's zen access.
            INotificationManager inm = NotificationManager.getService();
            inm.removeAutomaticZenRules(packageName);
            inm.setNotificationPolicyAccessGranted(packageName, false);
        } catch (RemoteException e) {
        }
    } finally {
        Binder.restoreCallingIdentity(callingId);
    }
    return true;
}
Also used : IPackageManager(android.content.pm.IPackageManager) INotificationManager(android.app.INotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) RemoteException(android.os.RemoteException) Point(android.graphics.Point) IPackageDataObserver(android.content.pm.IPackageDataObserver)

Example 49 with INotificationManager

use of android.app.INotificationManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ChannelNotificationSettingsTest method launchNotificationSettings_blockedChannel.

@Test
public void launchNotificationSettings_blockedChannel() throws Exception {
    NotificationChannel blocked = new NotificationChannel("blocked", "blocked", IMPORTANCE_NONE);
    mNm.createNotificationChannel(blocked);
    INotificationManager sINM = INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
    blocked.setImportance(IMPORTANCE_NONE);
    sINM.updateNotificationChannelForPackage(mTargetContext.getPackageName(), Process.myUid(), blocked);
    final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName()).putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId()).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mInstrumentation.startActivitySync(intent);
    onView(allOf(withText("At your request, Android is blocking this category of notifications" + " from appearing on this device"))).check(matches(isDisplayed()));
    try {
        onView(allOf(withText("On the lock screen"))).check(matches(isDisplayed()));
        fail("settings appearing for blocked channel");
    } catch (Exception e) {
    // expected
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) INotificationManager(android.app.INotificationManager) Intent(android.content.Intent) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Aggregations

INotificationManager (android.app.INotificationManager)49 RemoteException (android.os.RemoteException)28 SystemApi (android.annotation.SystemApi)10 Context (android.content.Context)4 Configuration (android.content.res.Configuration)4 Theme (android.content.res.Resources.Theme)4 IMountService (android.os.storage.IMountService)4 DisplayMetrics (android.util.DisplayMetrics)4 WindowManager (android.view.WindowManager)4 ILockSettings (com.android.internal.widget.ILockSettings)4 AccessibilityManagerService (com.android.server.accessibility.AccessibilityManagerService)4 AudioService (com.android.server.audio.AudioService)4 ClipboardService (com.android.server.clipboard.ClipboardService)4 DevicePolicyManagerService (com.android.server.devicepolicy.DevicePolicyManagerService)4 InputManagerService (com.android.server.input.InputManagerService)4 MediaRouterService (com.android.server.media.MediaRouterService)4 NetworkPolicyManagerService (com.android.server.net.NetworkPolicyManagerService)4 NetworkStatsService (com.android.server.net.NetworkStatsService)4 SchedulingPolicyService (com.android.server.os.SchedulingPolicyService)4 ShortcutService (com.android.server.pm.ShortcutService)4