Java Code Examples for android.app.ActivityManager#getService()

The following examples show how to use android.app.ActivityManager#getService() . 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: NotificationRecord.java    From android_9.0.0_r45 with Apache License 2.0 7 votes vote down vote up
public NotificationRecord(Context context, StatusBarNotification sbn,
        NotificationChannel channel) {
    this.sbn = sbn;
    mTargetSdkVersion = LocalServices.getService(PackageManagerInternal.class)
            .getPackageTargetSdkVersion(sbn.getPackageName());
    mAm = ActivityManager.getService();
    mOriginalFlags = sbn.getNotification().flags;
    mRankingTimeMs = calculateRankingTimeMs(0L);
    mCreationTimeMs = sbn.getPostTime();
    mUpdateTimeMs = mCreationTimeMs;
    mInterruptionTimeMs = mCreationTimeMs;
    mContext = context;
    stats = new NotificationUsageStats.SingleNotificationStats();
    mChannel = channel;
    mPreChannelsNotification = isPreChannelsNotification();
    mSound = calculateSound();
    mVibration = calculateVibration();
    mAttributes = calculateAttributes();
    mImportance = calculateImportance();
    mLight = calculateLights();
    mAdjustments = new ArrayList<>();
    mStats = new NotificationStats();
    calculateUserSentiment();
    calculateGrantableUris();
}
 
Example 2
Source File: SearchManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) {
    ComponentName comp = getLegacyAssistComponent(userHandle);
    if (comp == null) {
        return false;
    }
    long ident = Binder.clearCallingIdentity();
    try {
        Intent intent = new Intent(VoiceInteractionService.SERVICE_INTERFACE);
        intent.setComponent(comp);

        IActivityManager am = ActivityManager.getService();
        if (args != null) {
            args.putInt(Intent.EXTRA_KEY_EVENT, android.view.KeyEvent.KEYCODE_ASSIST);
        }
        intent.putExtras(args);

        return am.launchAssistIntent(intent, ActivityManager.ASSIST_CONTEXT_BASIC, hint,
                userHandle, args);
    } catch (RemoteException e) {
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
    return true;
}
 
Example 3
Source File: StorageManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * MediaProvider has a ton of code that makes assumptions about storage
 * paths never changing, so we outright kill them to pick up new state.
 */
@Deprecated
private void killMediaProvider(List<UserInfo> users) {
    if (users == null) return;

    final long token = Binder.clearCallingIdentity();
    try {
        for (UserInfo user : users) {
            // System user does not have media provider, so skip.
            if (user.isSystemOnly()) continue;

            final ProviderInfo provider = mPms.resolveContentProvider(MediaStore.AUTHORITY,
                    PackageManager.MATCH_DIRECT_BOOT_AWARE
                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
                    user.id);
            if (provider != null) {
                final IActivityManager am = ActivityManager.getService();
                try {
                    am.killApplication(provider.applicationInfo.packageName,
                            UserHandle.getAppId(provider.applicationInfo.uid),
                            UserHandle.USER_ALL, "vold reset");
                    // We only need to run this once. It will kill all users' media processes.
                    break;
                } catch (RemoteException e) {
                }
            }
        }
    } finally {
        Binder.restoreCallingIdentity(token);
    }
}
 
Example 4
Source File: PinnerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public PinnerService(Context context) {
    super(context);

    mContext = context;
    boolean shouldPinCamera = context.getResources().getBoolean(
            com.android.internal.R.bool.config_pinnerCameraApp);
    boolean shouldPinHome = context.getResources().getBoolean(
            com.android.internal.R.bool.config_pinnerHomeApp);
    if (shouldPinCamera) {
        mPinKeys.add(KEY_CAMERA);
    }
    if (shouldPinHome) {
        mPinKeys.add(KEY_HOME);
    }
    mPinnerHandler = new PinnerHandler(BackgroundThread.get().getLooper());

    mAmInternal = LocalServices.getService(ActivityManagerInternal.class);
    mAm = ActivityManager.getService();

    mUserManager = mContext.getSystemService(UserManager.class);

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    filter.addDataScheme("package");
    mContext.registerReceiver(mBroadcastReceiver, filter);

    registerUidListener();
    registerUserSetupCompleteListener();
}
 
Example 5
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private int runList(PrintWriter pw) throws RemoteException {
    final IActivityManager am = ActivityManager.getService();
    final List<UserInfo> users = getUsers(false);
    if (users == null) {
        pw.println("Error: couldn't get users");
        return 1;
    } else {
        pw.println("Users:");
        for (int i = 0; i < users.size(); i++) {
            String running = am.isUserRunning(users.get(i).id, 0) ? " running" : "";
            pw.println("\t" + users.get(i).toString() + running);
        }
        return 0;
    }
}
 
Example 6
Source File: OverlayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void updateAssets(final int userId, List<String> targetPackageNames) {
    updateOverlayPaths(userId, targetPackageNames);
    final IActivityManager am = ActivityManager.getService();
    try {
        am.scheduleApplicationInfoChanged(targetPackageNames, userId);
    } catch (RemoteException e) {
        // Intentionally left empty.
    }
}
 
Example 7
Source File: ClipboardService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates the clipboard.
 */
public ClipboardService(Context context) {
    super(context);

    mAm = ActivityManager.getService();
    mPm = getContext().getPackageManager();
    mUm = (IUserManager) ServiceManager.getService(Context.USER_SERVICE);
    mAppOps = (AppOpsManager) getContext().getSystemService(Context.APP_OPS_SERVICE);
    IBinder permOwner = null;
    try {
        permOwner = mAm.newUriPermissionOwner("clipboard");
    } catch (RemoteException e) {
        Slog.w("clipboard", "AM dead", e);
    }
    mPermissionOwner = permOwner;
    if (IS_EMULATOR) {
        mHostClipboardMonitor = new HostClipboardMonitor(
            new HostClipboardMonitor.HostClipboardCallback() {
                @Override
                public void onHostClipboardUpdated(String contents){
                    ClipData clip =
                        new ClipData("host clipboard",
                                     new String[]{"text/plain"},
                                     new ClipData.Item(contents));
                    synchronized(mClipboards) {
                        setPrimaryClipInternal(getClipboard(0), clip,
                                android.os.Process.SYSTEM_UID);
                    }
                }
            });
        mHostMonitorThread = new Thread(mHostClipboardMonitor);
        mHostMonitorThread.start();
    }
}
 
Example 8
Source File: StrictMode.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static void handleApplicationStrictModeViolation(int violationMaskSubset,
        ViolationInfo info) {
    final int oldMask = getThreadPolicyMask();
    try {
        // First, remove any policy before we call into the Activity Manager,
        // otherwise we'll infinite recurse as we try to log policy violations
        // to disk, thus violating policy, thus requiring logging, etc...
        // We restore the current policy below, in the finally block.
        setThreadPolicyMask(0);

        IActivityManager am = ActivityManager.getService();
        if (am == null) {
            Log.w(TAG, "No activity manager; failed to Dropbox violation.");
        } else {
            am.handleApplicationStrictModeViolation(
                    RuntimeInit.getApplicationObject(), violationMaskSubset, info);
        }
    } catch (RemoteException e) {
        if (e instanceof DeadObjectException) {
            // System process is dead; ignore
        } else {
            Log.e(TAG, "RemoteException handling StrictMode violation", e);
        }
    } finally {
        setThreadPolicyMask(oldMask);
    }
}
 
Example 9
Source File: SettingsHelper.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the locale specified. Input data is the byte representation of a
 * BCP-47 language tag. For backwards compatibility, strings of the form
 * {@code ll_CC} are also accepted, where {@code ll} is a two letter language
 * code and {@code CC} is a two letter country code.
 *
 * @param data the locale string in bytes.
 */
void setLocaleData(byte[] data, int size) {
    // Check if locale was set by the user:
    Configuration conf = mContext.getResources().getConfiguration();
    // TODO: The following is not working as intended because the network is forcing a locale
    // change after registering. Need to find some other way to detect if the user manually
    // changed the locale
    if (conf.userSetLocale) return; // Don't change if user set it in the SetupWizard

    final String[] availableLocales = mContext.getAssets().getLocales();
    // Replace "_" with "-" to deal with older backups.
    String localeCode = new String(data, 0, size).replace('_', '-');
    Locale loc = null;
    for (int i = 0; i < availableLocales.length; i++) {
        if (availableLocales[i].equals(localeCode)) {
            loc = Locale.forLanguageTag(localeCode);
            break;
        }
    }
    if (loc == null) return; // Couldn't find the saved locale in this version of the software

    try {
        IActivityManager am = ActivityManager.getService();
        Configuration config = am.getConfiguration();
        config.locale = loc;
        // indicate this isn't some passing default - the user wants this remembered
        config.userSetLocale = true;

        am.updateConfiguration(config);
    } catch (RemoteException e) {
        // Intentionally left blank
    }
}
 
Example 10
Source File: AppStateTracker.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
IActivityManager injectIActivityManager() {
    return ActivityManager.getService();
}
 
Example 11
Source File: LockSettingsService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public IActivityManager getActivityManager() {
    return ActivityManager.getService();
}
 
Example 12
Source File: BroadcastReceiver.java    From AndroidComponentPlugin with Apache License 2.0 3 votes vote down vote up
/**
 * Provide a binder to an already-bound service.  This method is synchronous
 * and will not start the target service if it is not present, so it is safe
 * to call from {@link #onReceive}.
 *
 * For peekService() to return a non null {@link android.os.IBinder} interface
 * the service must have published it before. In other words some component
 * must have called {@link android.content.Context#bindService(Intent, ServiceConnection, int)} on it.
 *
 * @param myContext The Context that had been passed to {@link #onReceive(Context, Intent)}
 * @param service Identifies the already-bound service you wish to use. See
 * {@link android.content.Context#bindService(Intent, ServiceConnection, int)}
 * for more information.
 */
public IBinder peekService(Context myContext, Intent service) {
    IActivityManager am = ActivityManager.getService();
    IBinder binder = null;
    try {
        service.prepareToLeaveProcess(myContext);
        binder = am.peekService(service, service.resolveTypeIfNeeded(
                myContext.getContentResolver()), myContext.getOpPackageName());
    } catch (RemoteException e) {
    }
    return binder;
}
 
Example 13
Source File: BroadcastReceiver.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Provide a binder to an already-bound service.  This method is synchronous
 * and will not start the target service if it is not present, so it is safe
 * to call from {@link #onReceive}.
 *
 * For peekService() to return a non null {@link android.os.IBinder} interface
 * the service must have published it before. In other words some component
 * must have called {@link android.content.Context#bindService(Intent, ServiceConnection, int)} on it.
 *
 * @param myContext The Context that had been passed to {@link #onReceive(Context, Intent)}
 * @param service Identifies the already-bound service you wish to use. See
 * {@link android.content.Context#bindService(Intent, ServiceConnection, int)}
 * for more information.
 */
public IBinder peekService(Context myContext, Intent service) {
    IActivityManager am = ActivityManager.getService();
    IBinder binder = null;
    try {
        service.prepareToLeaveProcess(myContext);
        binder = am.peekService(service, service.resolveTypeIfNeeded(
                myContext.getContentResolver()), myContext.getOpPackageName());
    } catch (RemoteException e) {
    }
    return binder;
}