コード例 #1
0
 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);
   }
 }
コード例 #2
0
  /**
   * 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;
    mContext.sendOrderedBroadcastAsUser(
        new Intent(Intent.ACTION_SHUTDOWN), 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);
  }
  boolean onKeyDown(int keyCode, KeyEvent event) {
    /* ****************************************************************************
     * HOW TO DECIDE WHERE YOUR KEY HANDLING GOES.
     * See the comment in PhoneWindow.onKeyDown
     * ****************************************************************************/
    final KeyEvent.DispatcherState dispatcher = mView.getKeyDispatcherState();

    switch (keyCode) {
      case KeyEvent.KEYCODE_VOLUME_UP:
      case KeyEvent.KEYCODE_VOLUME_DOWN:
      case KeyEvent.KEYCODE_VOLUME_MUTE:
        {
          MediaSessionLegacyHelper.getHelper(mContext).sendVolumeKeyEvent(event, false);
          return true;
        }

      case KeyEvent.KEYCODE_MEDIA_PLAY:
      case KeyEvent.KEYCODE_MEDIA_PAUSE:
      case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        /* Suppress PLAY/PAUSE toggle when phone is ringing or in-call
         * to avoid music playback */
        if (getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE) {
          return true; // suppress key event
        }
      case KeyEvent.KEYCODE_MUTE:
      case KeyEvent.KEYCODE_HEADSETHOOK:
      case KeyEvent.KEYCODE_MEDIA_STOP:
      case KeyEvent.KEYCODE_MEDIA_NEXT:
      case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
      case KeyEvent.KEYCODE_MEDIA_REWIND:
      case KeyEvent.KEYCODE_MEDIA_RECORD:
      case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
      case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
        {
          handleMediaKeyEvent(event);
          return true;
        }

      case KeyEvent.KEYCODE_CALL:
        {
          if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
            break;
          }
          if (event.getRepeatCount() == 0) {
            dispatcher.startTracking(event, this);
          } else if (event.isLongPress() && dispatcher.isTracking(event)) {
            dispatcher.performedLongPress(event);
            if (isUserSetupComplete()) {
              mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
              // launch the VoiceDialer
              Intent intent = new Intent(Intent.ACTION_VOICE_COMMAND);
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              try {
                sendCloseSystemWindows();
                mContext.startActivity(intent);
              } catch (ActivityNotFoundException e) {
                startCallActivity();
              }
            } else {
              Log.i(TAG, "Not starting call activity because user " + "setup is in progress.");
            }
          }
          return true;
        }

      case KeyEvent.KEYCODE_CAMERA:
        {
          if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
            break;
          }
          if (event.getRepeatCount() == 0) {
            dispatcher.startTracking(event, this);
          } else if (event.isLongPress() && dispatcher.isTracking(event)) {
            dispatcher.performedLongPress(event);
            if (isUserSetupComplete()) {
              mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
              sendCloseSystemWindows();
              // Broadcast an intent that the Camera button was longpressed
              Intent intent = new Intent(Intent.ACTION_CAMERA_BUTTON, null);
              intent.putExtra(Intent.EXTRA_KEY_EVENT, event);
              mContext.sendOrderedBroadcastAsUser(
                  intent, UserHandle.CURRENT_OR_SELF, null, null, null, 0, null, null);
            } else {
              Log.i(
                  TAG, "Not dispatching CAMERA long press because user " + "setup is in progress.");
            }
          }
          return true;
        }

      case KeyEvent.KEYCODE_SEARCH:
        {
          if (getKeyguardManager().inKeyguardRestrictedInputMode() || dispatcher == null) {
            break;
          }
          if (event.getRepeatCount() == 0) {
            dispatcher.startTracking(event, this);
          } else if (event.isLongPress() && dispatcher.isTracking(event)) {
            Configuration config = mContext.getResources().getConfiguration();
            if (config.keyboard == Configuration.KEYBOARD_NOKEYS
                || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) {
              if (isUserSetupComplete()) {
                // launch the search activity
                Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                try {
                  mView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                  sendCloseSystemWindows();
                  getSearchManager().stopSearch();
                  mContext.startActivity(intent);
                  // Only clear this if we successfully start the
                  // activity; otherwise we will allow the normal short
                  // press action to be performed.
                  dispatcher.performedLongPress(event);
                  return true;
                } catch (ActivityNotFoundException e) {
                  // Ignore
                }
              } else {
                Log.i(
                    TAG,
                    "Not dispatching SEARCH long press because user " + "setup is in progress.");
              }
            }
          }
          break;
        }
    }
    return false;
  }