Search in sources :

Example 16 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by DirtyUnicorns.

the class SettingsHelper method setLocaleData.

/**
     * 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();
    // Don't change if user set it in the SetupWizard
    if (conf.userSetLocale)
        return;
    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;
        }
    }
    // Couldn't find the saved locale in this version of the software
    if (loc == null)
        return;
    try {
        IActivityManager am = ActivityManagerNative.getDefault();
        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
    }
}
Also used : Locale(java.util.Locale) Configuration(android.content.res.Configuration) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 17 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by DirtyUnicorns.

the class StrictMode method dropboxViolationAsync.

/**
     * In the common case, as set by conditionallyEnableDebugLogging,
     * we're just dropboxing any violations but not showing a dialog,
     * not loggging, and not killing the process.  In these cases we
     * don't need to do a synchronous call to the ActivityManager.
     * This is used by both per-thread and vm-wide violations when
     * applicable.
     */
private static void dropboxViolationAsync(final int violationMaskSubset, final ViolationInfo info) {
    int outstanding = sDropboxCallsInFlight.incrementAndGet();
    if (outstanding > 20) {
        // What's going on?  Let's not make make the situation
        // worse and just not log.
        sDropboxCallsInFlight.decrementAndGet();
        return;
    }
    if (LOG_V)
        Log.d(TAG, "Dropboxing async; in-flight=" + outstanding);
    new Thread("callActivityManagerForStrictModeDropbox") {

        public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
            try {
                IActivityManager am = ActivityManagerNative.getDefault();
                if (am == null) {
                    Log.d(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);
                }
            }
            int outstanding = sDropboxCallsInFlight.decrementAndGet();
            if (LOG_V)
                Log.d(TAG, "Dropbox complete; in-flight=" + outstanding);
        }
    }.start();
}
Also used : ActivityThread(android.app.ActivityThread) IActivityManager(android.app.IActivityManager)

Example 18 with IActivityManager

use of android.app.IActivityManager in project XobotOS by xamarin.

the class BroadcastReceiver method peekService.

/**
     * Provide a binder to an already-running 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}.
     * 
     * @param myContext The Context that had been passed to {@link #onReceive(Context, Intent)}
     * @param service The Intent indicating the service you wish to use.  See {@link
     * Context#startService(Intent)} for more information.
     */
public IBinder peekService(Context myContext, Intent service) {
    IActivityManager am = ActivityManagerNative.getDefault();
    IBinder binder = null;
    try {
        service.setAllowFds(false);
        binder = am.peekService(service, service.resolveTypeIfNeeded(myContext.getContentResolver()));
    } catch (RemoteException e) {
    }
    return binder;
}
Also used : IBinder(android.os.IBinder) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 19 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by AOSPA.

the class Dpm method parseArgs.

private void parseArgs(boolean canHaveName) {
    String opt;
    while ((opt = nextOption()) != null) {
        if ("--user".equals(opt)) {
            String arg = nextArgRequired();
            if ("current".equals(arg) || "cur".equals(arg)) {
                mUserId = UserHandle.USER_CURRENT;
            } else {
                mUserId = parseInt(arg);
            }
            if (mUserId == UserHandle.USER_CURRENT) {
                IActivityManager activityManager = ActivityManagerNative.getDefault();
                try {
                    mUserId = activityManager.getCurrentUser().id;
                } catch (RemoteException e) {
                    e.rethrowAsRuntimeException();
                }
            }
        } else if (canHaveName && "--name".equals(opt)) {
            mName = nextArgRequired();
        } else {
            throw new IllegalArgumentException("Unknown option: " + opt);
        }
    }
    mComponent = parseComponentName(nextArgRequired());
}
Also used : RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 20 with IActivityManager

use of android.app.IActivityManager in project android_frameworks_base by DirtyUnicorns.

the class ShutdownThread method run.

/**
     * Makes sure we handle the shutdown gracefully.
     * Shuts off power regardless of radio and bluetooth state if the alloted time has passed.
     */
public void run() {
    BroadcastReceiver br = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // We don't allow apps to cancel this, so ignore the result.
            actionDone();
        }
    };
    /*
         * Write a system property in case the system_server reboots before we
         * get to the actual hardware restart. If that happens, we'll retry at
         * the beginning of the SystemServer startup.
         */
    {
        String reason = (mReboot ? "1" : "0") + (mReason != null ? mReason : "");
        SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason);
    }
    /*
         * If we are rebooting into safe mode, write a system property
         * indicating so.
         */
    if (mRebootSafeMode) {
        SystemProperties.set(REBOOT_SAFEMODE_PROPERTY, "1");
    }
    Log.i(TAG, "Sending shutdown broadcast...");
    // First send the high-level shut down broadcast.
    mActionDone = false;
    Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, null, br, mHandler, 0, null, null);
    final long endTime = SystemClock.elapsedRealtime() + MAX_BROADCAST_TIME;
    synchronized (mActionDoneSync) {
        while (!mActionDone) {
            long delay = endTime - SystemClock.elapsedRealtime();
            if (delay <= 0) {
                Log.w(TAG, "Shutdown broadcast timed out");
                break;
            } else if (mRebootHasProgressBar) {
                int status = (int) ((MAX_BROADCAST_TIME - delay) * 1.0 * BROADCAST_STOP_PERCENT / MAX_BROADCAST_TIME);
                sInstance.setRebootProgress(status, null);
            }
            try {
                mActionDoneSync.wait(Math.min(delay, PHONE_STATE_POLL_SLEEP_MSEC));
            } catch (InterruptedException e) {
            }
        }
    }
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(BROADCAST_STOP_PERCENT, null);
    }
    Log.i(TAG, "Shutting down activity manager...");
    final IActivityManager am = ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
    if (am != null) {
        try {
            am.shutdown(MAX_BROADCAST_TIME);
        } catch (RemoteException e) {
        }
    }
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(ACTIVITY_MANAGER_STOP_PERCENT, null);
    }
    Log.i(TAG, "Shutting down package manager...");
    final PackageManagerService pm = (PackageManagerService) ServiceManager.getService("package");
    if (pm != null) {
        pm.shutdown();
    }
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(PACKAGE_MANAGER_STOP_PERCENT, null);
    }
    // Shutdown radios.
    shutdownRadios(MAX_RADIO_WAIT_TIME);
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(RADIO_STOP_PERCENT, null);
    }
    // Shutdown MountService to ensure media is in a safe state
    IMountShutdownObserver observer = new IMountShutdownObserver.Stub() {

        public void onShutDownComplete(int statusCode) throws RemoteException {
            Log.w(TAG, "Result code " + statusCode + " from MountService.shutdown");
            actionDone();
        }
    };
    Log.i(TAG, "Shutting down MountService");
    // Set initial variables and time out time.
    mActionDone = false;
    final long endShutTime = SystemClock.elapsedRealtime() + MAX_SHUTDOWN_WAIT_TIME;
    synchronized (mActionDoneSync) {
        try {
            final IMountService mount = IMountService.Stub.asInterface(ServiceManager.checkService("mount"));
            if (mount != null) {
                mount.shutdown(observer);
            } else {
                Log.w(TAG, "MountService unavailable for shutdown");
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception during MountService shutdown", e);
        }
        while (!mActionDone) {
            long delay = endShutTime - SystemClock.elapsedRealtime();
            if (delay <= 0) {
                Log.w(TAG, "Shutdown wait timed out");
                break;
            } else if (mRebootHasProgressBar) {
                int status = (int) ((MAX_SHUTDOWN_WAIT_TIME - delay) * 1.0 * (MOUNT_SERVICE_STOP_PERCENT - RADIO_STOP_PERCENT) / MAX_SHUTDOWN_WAIT_TIME);
                status += RADIO_STOP_PERCENT;
                sInstance.setRebootProgress(status, null);
            }
            try {
                mActionDoneSync.wait(Math.min(delay, PHONE_STATE_POLL_SLEEP_MSEC));
            } catch (InterruptedException e) {
            }
        }
    }
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(MOUNT_SERVICE_STOP_PERCENT, null);
        // If it's to reboot to install an update and uncrypt hasn't been
        // done yet, trigger it now.
        uncrypt();
    }
    rebootOrShutdown(mContext, mReboot, mReason);
}
Also used : Context(android.content.Context) IMountShutdownObserver(android.os.storage.IMountShutdownObserver) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) RemoteException(android.os.RemoteException) ErrnoException(android.system.ErrnoException) IOException(java.io.IOException) PackageManagerService(com.android.server.pm.PackageManagerService) IMountService(android.os.storage.IMountService) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Aggregations

IActivityManager (android.app.IActivityManager)112 RemoteException (android.os.RemoteException)93 Intent (android.content.Intent)23 IBinder (android.os.IBinder)20 Configuration (android.content.res.Configuration)15 UserHandle (android.os.UserHandle)14 ContentProviderHolder (android.app.IActivityManager.ContentProviderHolder)11 IContentProvider (android.content.IContentProvider)11 Binder (android.os.Binder)11 ActivityOptions (android.app.ActivityOptions)9 ActivityThread (android.app.ActivityThread)9 Context (android.content.Context)8 IntentSender (android.content.IntentSender)8 Point (android.graphics.Point)7 SpannableString (android.text.SpannableString)7 BroadcastReceiver (android.content.BroadcastReceiver)6 ComponentName (android.content.ComponentName)6 IMountService (android.os.storage.IMountService)6 IMountShutdownObserver (android.os.storage.IMountShutdownObserver)6 Locale (java.util.Locale)6