Search in sources :

Example 96 with Context

use of android.content.Context in project android_frameworks_base by ParanoidAndroid.

the class ServiceRecord method postNotification.

public void postNotification() {
    final int appUid = appInfo.uid;
    final int appPid = app.pid;
    if (foregroundId != 0 && foregroundNoti != null) {
        // Do asynchronous communication with notification manager to
        // avoid deadlocks.
        final String localPackageName = packageName;
        final int localForegroundId = foregroundId;
        final Notification localForegroundNoti = foregroundNoti;
        ams.mHandler.post(new Runnable() {

            public void run() {
                NotificationManagerService nm = (NotificationManagerService) NotificationManager.getService();
                if (nm == null) {
                    return;
                }
                try {
                    if (localForegroundNoti.icon == 0) {
                        // It is not correct for the caller to supply a notification
                        // icon, but this used to be able to slip through, so for
                        // those dirty apps give it the app's icon.
                        localForegroundNoti.icon = appInfo.icon;
                        // Do not allow apps to present a sneaky invisible content view either.
                        localForegroundNoti.contentView = null;
                        localForegroundNoti.bigContentView = null;
                        CharSequence appName = appInfo.loadLabel(ams.mContext.getPackageManager());
                        if (appName == null) {
                            appName = appInfo.packageName;
                        }
                        Context ctx = null;
                        try {
                            ctx = ams.mContext.createPackageContext(appInfo.packageName, 0);
                            Intent runningIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            runningIntent.setData(Uri.fromParts("package", appInfo.packageName, null));
                            PendingIntent pi = PendingIntent.getActivity(ams.mContext, 0, runningIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                            localForegroundNoti.setLatestEventInfo(ctx, ams.mContext.getString(com.android.internal.R.string.app_running_notification_title, appName), ams.mContext.getString(com.android.internal.R.string.app_running_notification_text, appName), pi);
                        } catch (PackageManager.NameNotFoundException e) {
                            localForegroundNoti.icon = 0;
                        }
                    }
                    if (localForegroundNoti.icon == 0) {
                        // being foreground.
                        throw new RuntimeException("icon must be non-zero");
                    }
                    int[] outId = new int[1];
                    nm.enqueueNotificationInternal(localPackageName, localPackageName, appUid, appPid, null, localForegroundId, localForegroundNoti, outId, userId);
                } catch (RuntimeException e) {
                    Slog.w(ActivityManagerService.TAG, "Error showing notification for service", e);
                    // If it gave us a garbage notification, it doesn't
                    // get to be foreground.
                    ams.setServiceForeground(name, ServiceRecord.this, 0, null, true);
                    ams.crashApplication(appUid, appPid, localPackageName, "Bad notification for startForeground: " + e);
                }
            }
        });
    }
}
Also used : NotificationManagerService(com.android.server.NotificationManagerService) Context(android.content.Context) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 97 with Context

use of android.content.Context in project android_frameworks_base by ParanoidAndroid.

the class InputManagerService method start.

public void start() {
    Slog.i(TAG, "Starting input manager");
    nativeStart(mPtr);
    // Add ourself to the Watchdog monitors.
    Watchdog.getInstance().addMonitor(this);
    registerPointerSpeedSettingObserver();
    registerShowTouchesSettingObserver();
    mContext.registerReceiver(new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            updatePointerSpeedFromSettings();
            updateShowTouchesFromSettings();
        }
    }, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
    updatePointerSpeedFromSettings();
    updateShowTouchesFromSettings();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 98 with Context

use of android.content.Context in project android_frameworks_base by ParanoidAndroid.

the class UserManagerService method finishRemoveUser.

void finishRemoveUser(final int userHandle) {
    if (DBG)
        Slog.i(LOG_TAG, "finishRemoveUser " + userHandle);
    // Let other services shutdown any activity and clean up their state before completely
    // wiping the user's system directory and removing from the user list
    long ident = Binder.clearCallingIdentity();
    try {
        Intent addedIntent = new Intent(Intent.ACTION_USER_REMOVED);
        addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle);
        mContext.sendOrderedBroadcastAsUser(addedIntent, UserHandle.ALL, android.Manifest.permission.MANAGE_USERS, new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (DBG) {
                    Slog.i(LOG_TAG, "USER_REMOVED broadcast sent, cleaning up user data " + userHandle);
                }
                new Thread() {

                    public void run() {
                        synchronized (mInstallLock) {
                            synchronized (mPackagesLock) {
                                removeUserStateLocked(userHandle);
                            }
                        }
                    }
                }.start();
            }
        }, null, Activity.RESULT_OK, null, null);
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
Also used : Context(android.content.Context) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 99 with Context

use of android.content.Context in project android_frameworks_base by ParanoidAndroid.

the class AppTransition method loadAnimation.

Animation loadAnimation(WindowManager.LayoutParams lp, int animAttr) {
    int anim = 0;
    Context context = mContext;
    if (animAttr >= 0) {
        AttributeCache.Entry ent = getCachedAnimations(lp);
        if (ent != null) {
            context = ent.context;
            anim = ent.array.getResourceId(animAttr, 0);
        }
    }
    if (anim != 0) {
        return AnimationUtils.loadAnimation(context, anim);
    }
    return null;
}
Also used : Context(android.content.Context) AttributeCache(com.android.server.AttributeCache) Point(android.graphics.Point)

Example 100 with Context

use of android.content.Context in project android_frameworks_base by ParanoidAndroid.

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") + (mRebootReason != null ? mRebootReason : "");
        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;
            }
            try {
                mActionDoneSync.wait(delay);
            } catch (InterruptedException e) {
            }
        }
    }
    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) {
        }
    }
    // Shutdown radios.
    shutdownRadios(MAX_RADIO_WAIT_TIME);
    // 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;
            }
            try {
                mActionDoneSync.wait(delay);
            } catch (InterruptedException e) {
            }
        }
    }
    rebootOrShutdown(mReboot, mRebootReason);
}
Also used : Context(android.content.Context) IMountShutdownObserver(android.os.storage.IMountShutdownObserver) IMountService(android.os.storage.IMountService) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) RemoteException(android.os.RemoteException) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Aggregations

Context (android.content.Context)3081 Intent (android.content.Intent)651 View (android.view.View)382 BroadcastReceiver (android.content.BroadcastReceiver)334 IntentFilter (android.content.IntentFilter)292 Test (org.junit.Test)265 TextView (android.widget.TextView)241 Resources (android.content.res.Resources)223 PendingIntent (android.app.PendingIntent)186 PackageManager (android.content.pm.PackageManager)157 File (java.io.File)141 IOException (java.io.IOException)139 ImageView (android.widget.ImageView)130 LayoutInflater (android.view.LayoutInflater)129 Drawable (android.graphics.drawable.Drawable)124 Uri (android.net.Uri)107 RemoteException (android.os.RemoteException)102 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)99 Bundle (android.os.Bundle)93 ArrayList (java.util.ArrayList)92