@Override
 protected Void doInBackground(Void... params) {
   String[] services;
   try {
     services = ServiceManager.listServices();
   } catch (RemoteException e) {
     return null;
   }
   for (String service : services) {
     IBinder obj = ServiceManager.checkService(service);
     if (obj != null) {
       Parcel data = Parcel.obtain();
       try {
         obj.transact(IBinder.SYSPROPS_TRANSACTION, data, null, 0);
       } catch (RemoteException e) {
       } catch (Exception e) {
         Log.i(
             "DevSettings",
             "Somone wrote a bad service '" + service + "' that doesn't like to be poked: " + e);
       }
       data.recycle();
     }
   }
   return null;
 }
  /**
   * Attach to the required system interfaces.
   *
   * @return Returns true if all system interfaces were available.
   */
  private boolean getSystemInterfaces() {
    mAm = ActivityManagerNative.getDefault();
    if (mAm == null) {
      System.err.println(
          "** Error: Unable to connect to activity manager; is the system " + "running?");
      return false;
    }

    mWm = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
    if (mWm == null) {
      System.err.println(
          "** Error: Unable to connect to window manager; is the system " + "running?");
      return false;
    }

    mPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
    if (mPm == null) {
      System.err.println(
          "** Error: Unable to connect to package manager; is the system " + "running?");
      return false;
    }

    try {
      mAm.setActivityController(new ActivityController());
      mNetworkMonitor.register(mAm);
    } catch (RemoteException e) {
      System.err.println("** Failed talking with activity manager!");
      return false;
    }

    return true;
  }
Пример #3
0
  public BrightnessController(Context context, ImageView icon, ToggleSlider control) {
    mContext = context;
    mIcon = icon;
    mControl = control;
    mHandler = new Handler();
    mUserTracker =
        new CurrentUserTracker(mContext) {
          @Override
          public void onUserSwitched(int newUserId) {
            updateMode();
            updateSlider();
          }
        };
    mBrightnessObserver = new BrightnessObserver(mHandler);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    mMinimumBacklight = pm.getMinimumScreenBrightnessSetting();
    mMaximumBacklight = pm.getMaximumScreenBrightnessSetting();

    mAutomaticAvailable =
        context
            .getResources()
            .getBoolean(com.android.internal.R.bool.config_automatic_brightness_available);
    mPower = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));
  }
Пример #4
0
  @Override
  public void onCreate() {
    // Pick status bar or system bar.
    IWindowManager wm =
        IWindowManager.Stub.asInterface(ServiceManager.getService(Context.WINDOW_SERVICE));
    try {
      SERVICES[0] =
          wm.canStatusBarHide()
              // ? R.string.config_statusBarComponent
              ? R.string.config_systemBarComponent
              : R.string.config_systemBarComponent;
    } catch (RemoteException e) {
      Slog.w(TAG, "Failing checking whether status bar can hide", e);
    }

    final int N = SERVICES.length;
    mServices = new SystemUI[N];
    for (int i = 0; i < N; i++) {
      Class cl = chooseClass(SERVICES[i]);
      Slog.d(TAG, "loading: " + cl);
      try {
        mServices[i] = (SystemUI) cl.newInstance();
      } catch (IllegalAccessException ex) {
        throw new RuntimeException(ex);
      } catch (InstantiationException ex) {
        throw new RuntimeException(ex);
      }
      mServices[i].mContext = this;
      Slog.d(TAG, "running: " + mServices[i]);
      mServices[i].start();
    }
  }
Пример #5
0
  public BatteryService(Context context, LightsService lights) {
    mContext = context;
    mHandler = new Handler(true /*async*/);
    mLed = new Led(context, lights);
    mBatteryStats = BatteryStatsService.getService();

    mCriticalBatteryLevel =
        mContext
            .getResources()
            .getInteger(com.android.internal.R.integer.config_criticalBatteryWarningLevel);
    mLowBatteryWarningLevel =
        mContext
            .getResources()
            .getInteger(com.android.internal.R.integer.config_lowBatteryWarningLevel);
    mLowBatteryCloseWarningLevel =
        mContext
            .getResources()
            .getInteger(com.android.internal.R.integer.config_lowBatteryCloseWarningLevel);
    mShutdownBatteryTemperature =
        mContext
            .getResources()
            .getInteger(com.android.internal.R.integer.config_shutdownBatteryTemperature);

    // watch for invalid charger messages if the invalid_charger switch exists
    if (new File("/sys/devices/virtual/switch/invalid_charger/state").exists()) {
      mInvalidChargerObserver.startObserving("DEVPATH=/devices/virtual/switch/invalid_charger");
    }

    mBatteryPropertiesListener = new BatteryListener();

    IBinder b = ServiceManager.getService("batterypropreg");
    mBatteryPropertiesRegistrar = IBatteryPropertiesRegistrar.Stub.asInterface(b);

    try {
      mBatteryPropertiesRegistrar.registerListener(mBatteryPropertiesListener);
    } catch (RemoteException e) {
      // Should never happen.
    }
    if (FeatureOption.MTK_IPO_SUPPORT == true) {
      IntentFilter filter = new IntentFilter();
      filter.addAction(IPO_POWER_ON);
      filter.addAction(IPO_POWER_OFF);
      mContext.registerReceiver(
          new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
              if (IPO_POWER_ON.equals(intent.getAction())) {
                mIPOShutdown = false;
                mIPOBoot = true;
                // Let BatteryService to handle low battery warning.
                mLastBatteryLevel = mLowBatteryWarningLevel + 1;
                update(mBatteryProps);
              } else if (IPO_POWER_OFF.equals(intent.getAction())) {
                mIPOShutdown = true;
              }
            }
          },
          filter);
    }
  }
Пример #6
0
 /** Starts the SIP service. Do nothing if the SIP API is not supported on the device. */
 public static void start(Context context) {
   if (SipManager.isApiSupported(context)) {
     ServiceManager.addService("sip", new SipService(context));
     context.sendBroadcast(new Intent(SipManager.ACTION_SIP_SERVICE_UP));
     if (DEBUG) Log.d(TAG, "SIP service started");
   }
 }
 @Override
 public void run() {
   try {
     if (DEBUG) {
       Log.v(TAG, "call supplyPinReportResultForSubscriber(subid=" + mSubId + ")");
     }
     final int[] result =
         ITelephony.Stub.asInterface(ServiceManager.checkService("phone"))
             .supplyPinReportResultForSubscriber(mSubId, mPin);
     if (DEBUG) {
       Log.v(TAG, "supplyPinReportResult returned: " + result[0] + " " + result[1]);
     }
     post(
         new Runnable() {
           public void run() {
             onSimCheckResponse(result[0], result[1]);
           }
         });
   } catch (RemoteException e) {
     Log.e(TAG, "RemoteException for supplyPinReportResult:", e);
     post(
         new Runnable() {
           public void run() {
             onSimCheckResponse(PhoneConstants.PIN_GENERAL_FAILURE, -1);
           }
         });
   }
 }
Пример #8
0
  protected void setUp() {
    android.os.IBinder binder = android.os.ServiceManager.getService("DmAgent");
    Assert.assertNotNull("get DmAgent service failed.", binder);

    mAgent = DmAgent.Stub.asInterface(binder);
    Assert.assertNotNull("DmAgent asInterface failed.", mAgent);
  }
 private IMountService getMountService() {
   IBinder service = ServiceManager.getService("mount");
   if (service != null) {
     return IMountService.Stub.asInterface(service);
   }
   return null;
 }
 /**
  * while receiving one sms, check the sms count to see whether it reaches the max count.
  *
  * @param threadId
  * @param context
  * @param flag indicate the operator (increase/decrease)
  * @return true if the count is less than the max size, otherwise false.
  */
 public void isFull(Long threadId, Context context, int flag) {
   try {
     ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
     if (phone != null) {
       if (phone.isTestIccCard()
           || (Integer.parseInt(SystemProperties.get("gsm.gcf.testmode", "0")) == 2)) {
         Log.d(TAG, "Now using test icc card...");
         if (flag == OP_FLAG_INCREASE) {
           if (get(threadId, context) >= THREAD_MAX_SIZE) {
             Log.d(TAG, "Storage is full. send notification...");
             SmsManager.getDefault().setSmsMemoryStatus(false);
           }
         } else if (flag == OP_FLAG_DECREASE) {
           if (get(threadId, context) < THREAD_MAX_SIZE) {
             Log.d(TAG, "Storage is available. send notification...");
             SmsManager.getDefault().setSmsMemoryStatus(true);
           }
         }
       }
     } else {
       Log.d(TAG, "Telephony service is not available!");
     }
   } catch (Exception ex) {
     Log.e(TAG, " " + ex.getMessage());
   }
 }
Пример #11
0
  private void test11GetImei() {
    Log.i(TAG, "test11GetImei call getDeviceIdGemini()");
    String imei1 = null;
    String imei2 = null;
    long[] subIds = null;

    try {
      IPhoneSubInfo subInfo =
          IPhoneSubInfo.Stub.asInterface(ServiceManager.getService("iphonesubinfo"));
      // Sim 1
      subIds = SubscriptionManager.getSubIdUsingSlotId(0);
      if (subIds != null && subIds.length > 0 && subIds[0] > 0) {
        Log.i(TAG, "Find slot 0 with subId: " + subIds[0]);
        imei1 = subInfo.getDeviceIdForSubscriber(subIds[0]);
      }
      // Sim 2
      subIds = SubscriptionManager.getSubIdUsingSlotId(1);
      if (subIds != null && subIds.length > 0 && subIds[0] > 0) {
        imei2 = subInfo.getDeviceIdForSubscriber(subIds[0]);
        Log.i(TAG, "Find slot 1 with subId: " + subIds[0]);
      }
    } catch (RemoteException e) {
      Log.e(TAG, e.toString());
    }

    Log.i(TAG, "test11GetImei call getDeviceIdGemini() " + imei1 + " " + imei2);
    Bundle bundle = new Bundle();
    bundle.putString(KEY_IMEI1, imei1);
    bundle.putString(KEY_IMEI2, imei2);

    removeDialog(DIALOG_IMEI);
    showDialog(DIALOG_IMEI, bundle);
  }
Пример #12
0
  /** Begin monitoring connectivity */
  public void startMonitoring(Context context, Handler target) {
    mContext = context;
    mCsHandler = target;

    // register for notifications from NetworkManagement Service
    IBinder b = ServiceManager.getService(Context.NETWORKMANAGEMENT_SERVICE);
    INetworkManagementService service = INetworkManagementService.Stub.asInterface(b);

    mInterfaceObserver = new InterfaceObserver(this);

    // enable and try to connect to an ethernet interface that
    // already exists
    sIfaceMatch =
        context.getResources().getString(com.android.internal.R.string.config_ethernet_iface_regex);
    try {
      final String[] ifaces = service.listInterfaces();
      for (String iface : ifaces) {
        if (iface.matches(sIfaceMatch)) {
          mIface = iface;
          InterfaceConfiguration config = service.getInterfaceConfig(iface);
          mLinkUp = config.isActive();
          reconnect();
          break;
        }
      }
    } catch (RemoteException e) {
      Log.e(TAG, "Could not get list of interfaces " + e);
    }

    try {
      service.registerObserver(mInterfaceObserver);
    } catch (RemoteException e) {
      Log.e(TAG, "Could not register InterfaceObserver " + e);
    }
  }
Пример #13
0
  /**
   * Class constructor.
   *
   * @param audioSource the recording source. See {@link MediaRecorder.AudioSource} for recording
   *     source definitions.
   * @param sampleRateInHz the sample rate expressed in Hertz. 44100Hz is currently the only rate
   *     that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025
   *     may work on some devices.
   * @param channelConfig describes the configuration of the audio channels. See {@link
   *     AudioFormat#CHANNEL_IN_MONO} and {@link AudioFormat#CHANNEL_IN_STEREO}. {@link
   *     AudioFormat#CHANNEL_IN_MONO} is guaranteed to work on all devices.
   * @param audioFormat the format in which the audio data is represented. See {@link
   *     AudioFormat#ENCODING_PCM_16BIT} and {@link AudioFormat#ENCODING_PCM_8BIT}
   * @param bufferSizeInBytes the total size (in bytes) of the buffer where audio data is written to
   *     during the recording. New audio data can be read from this buffer in smaller chunks than
   *     this size. See {@link #getMinBufferSize(int, int, int)} to determine the minimum required
   *     buffer size for the successful creation of an AudioRecord instance. Using values smaller
   *     than getMinBufferSize() will result in an initialization failure.
   * @throws java.lang.IllegalArgumentException
   */
  public AudioRecord(
      int audioSource,
      int sampleRateInHz,
      int channelConfig,
      int audioFormat,
      int bufferSizeInBytes)
      throws IllegalArgumentException {
    /// M: Check record permission to user for CTA. {@
    if (FeatureOption.MTK_MOBILE_MANAGEMENT) {
      Xlog.d(TAG, "AudioRecord>>>");
      IBinder binder = ServiceManager.getService(Context.MOBILE_SERVICE);
      IMobileManagerService moms = IMobileManagerService.Stub.asInterface(binder);
      int uid = Binder.getCallingUid();
      String permission = SubPermissions.RECORD_MIC;
      try {
        if (moms != null
            && (moms.checkPermission(permission, uid) != PackageManager.PERMISSION_GRANTED)) {
          Xlog.d(TAG, "AudioRecord<<<: user denied permission " + permission + " for uid " + uid);
          throw new IllegalArgumentException();
        }
      } catch (RemoteException e) {
        Xlog.e(TAG, "CheckPermission failed in prepare with RemoteException, continues record.", e);
      }
    }
    /// @}

    mRecordingState = RECORDSTATE_STOPPED;

    // remember which looper is associated with the AudioRecord instanciation
    if ((mInitializationLooper = Looper.myLooper()) == null) {
      mInitializationLooper = Looper.getMainLooper();
    }

    audioParamCheck(audioSource, sampleRateInHz, channelConfig, audioFormat);

    audioBuffSizeCheck(bufferSizeInBytes);

    // native initialization
    int[] session = new int[1];
    session[0] = 0;
    // TODO: update native initialization when information about hardware init failure
    //      due to capture device already open is available.
    int initResult =
        native_setup(
            new WeakReference<AudioRecord>(this),
            mRecordSource,
            mSampleRate,
            mChannelMask,
            mAudioFormat,
            mNativeBufferSizeInBytes,
            session);
    if (initResult != SUCCESS) {
      loge("Error code " + initResult + " when initializing native AudioRecord object.");
      return; // with mState == STATE_UNINITIALIZED
    }

    mSessionId = session[0];

    mState = STATE_INITIALIZED;
  }
Пример #14
0
 private DevicePolicyManager(Context context, Handler handler) {
   mContext = context;
   mHandler = handler;
   mService =
       IDevicePolicyManager.Stub.asInterface(
           ServiceManager.getService(Context.DEVICE_POLICY_SERVICE));
 }
Пример #15
0
 private static INotificationManager getService() {
   if (sService != null) {
     return sService;
   }
   sService = INotificationManager.Stub.asInterface(ServiceManager.getService("notification"));
   return sService;
 }
 private void updateFlingerOptions() {
   // magic communication with surface flinger.
   try {
     IBinder flinger = ServiceManager.getService("SurfaceFlinger");
     if (flinger != null) {
       Parcel data = Parcel.obtain();
       Parcel reply = Parcel.obtain();
       data.writeInterfaceToken("android.ui.ISurfaceComposer");
       flinger.transact(1010, data, reply, 0);
       @SuppressWarnings("unused")
       int showCpu = reply.readInt();
       @SuppressWarnings("unused")
       int enableGL = reply.readInt();
       int showUpdates = reply.readInt();
       updateCheckBox(mShowScreenUpdates, showUpdates != 0);
       @SuppressWarnings("unused")
       int showBackground = reply.readInt();
       int disableOverlays = reply.readInt();
       updateCheckBox(mDisableOverlays, disableOverlays != 0);
       reply.recycle();
       data.recycle();
     }
   } catch (RemoteException ex) {
   }
 }
 public PplSettingsEntryPlugin(Context context) {
   super(context);
   mContext = context;
   IBinder binder = ServiceManager.getService("PPLAgent");
   if (binder == null) {
     throw new Error("Failed to get PPLAgent");
   }
   mAgent = IPplAgent.Stub.asInterface(binder);
   if (mAgent == null) {
     throw new Error("mAgent is null!");
   }
   mPreference = new Preference(context);
   mPreference.setTitle(R.string.app_name);
   mPreference.setSummary(R.string.status_pending);
   mSimTracker = new SimTracker(PlatformManager.SIM_NUMBER, mContext);
   mNoSimListener =
       new OnPreferenceClickListener() {
         @Override
         public boolean onPreferenceClick(Preference preference) {
           Toast toast = Toast.makeText(mContext, R.string.toast_no_sim, Toast.LENGTH_SHORT);
           toast.show();
           return true;
         }
       };
   mEnabledListener =
       new OnPreferenceClickListener() {
         @Override
         public boolean onPreferenceClick(Preference preference) {
           // enter access lock
           Intent intent = new Intent();
           intent.setClass(mContext, AccessLockActivity.class);
           intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           startActivity(intent);
           return true;
         }
       };
   mProvisionedListener =
       new OnPreferenceClickListener() {
         @Override
         public boolean onPreferenceClick(Preference preference) {
           Intent intent = new Intent();
           intent.setClass(mContext, ChooseEnableModeActivity.class);
           intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           startActivity(intent);
           return true;
         }
       };
   mNotProvisionedListener =
       new OnPreferenceClickListener() {
         @Override
         public boolean onPreferenceClick(Preference preference) {
           Intent intent = new Intent();
           intent.setClass(mContext, SetupPasswordActivity.class);
           intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
           startActivity(intent);
           return true;
         }
       };
 }
Пример #18
0
 /** get handle to NFC service interface */
 private static INfcAdapter getServiceInterface() {
   /* get a handle to NFC service */
   IBinder b = ServiceManager.getService("nfc");
   if (b == null) {
     return null;
   }
   return INfcAdapter.Stub.asInterface(b);
 }
Пример #19
0
 public static void exec(int location, Context context) {
   try {
     IPackageManager mPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
     mPm.setInstallLocation(location);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
 public static IBatteryStats getService() {
   if (sService != null) {
     return sService;
   }
   IBinder b = ServiceManager.getService("batteryinfo");
   sService = asInterface(b);
   return sService;
 }
Пример #21
0
  public void run(String[] args) {
    boolean validCommand = false;
    if (args.length < 1) {
      showUsage();
      return;
    }

    mPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
    if (mPm == null) {
      System.err.println(PM_NOT_RUNNING_ERR);
      return;
    }

    mArgs = args;
    String op = args[0];
    mNextArg = 1;

    if ("list".equals(op)) {
      runList();
      return;
    }

    if ("path".equals(op)) {
      runPath();
      return;
    }

    if ("install".equals(op)) {
      runInstall();
      return;
    }

    if ("uninstall".equals(op)) {
      runUninstall();
      return;
    }

    try {
      if (args.length == 1) {
        if (args[0].equalsIgnoreCase("-l")) {
          validCommand = true;
          runListPackages(false);
        } else if (args[0].equalsIgnoreCase("-lf")) {
          validCommand = true;
          runListPackages(true);
        }
      } else if (args.length == 2) {
        if (args[0].equalsIgnoreCase("-p")) {
          validCommand = true;
          displayPackageFilePath(args[1]);
        }
      }
    } finally {
      if (validCommand == false) {
        showUsage();
      }
    }
  }
 protected IStatusBarService getStatusBarService() {
   synchronized (mServiceAquireLock) {
     if (mStatusBarService == null) {
       mStatusBarService =
           IStatusBarService.Stub.asInterface(ServiceManager.getService("statusbar"));
     }
     return mStatusBarService;
   }
 }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mPackageName = getCallingPackage();
    IBinder b = ServiceManager.getService(MEDIA_PROJECTION_SERVICE);
    mService = IMediaProjectionManager.Stub.asInterface(b);

    if (mPackageName == null) {
      finish();
      return;
    }

    PackageManager packageManager = getPackageManager();
    ApplicationInfo aInfo;
    try {
      aInfo = packageManager.getApplicationInfo(mPackageName, 0);
      mUid = aInfo.uid;
    } catch (PackageManager.NameNotFoundException e) {
      Log.e(TAG, "unable to look up package name", e);
      finish();
      return;
    }

    try {
      if (mService.hasProjectionPermission(mUid, mPackageName)) {
        setResult(
            RESULT_OK, getMediaProjectionIntent(mUid, mPackageName, false /*permanentGrant*/));
        finish();
        return;
      }
    } catch (RemoteException e) {
      Log.e(TAG, "Error checking projection permissions", e);
      finish();
      return;
    }

    String appName = aInfo.loadLabel(packageManager).toString();

    mDialog =
        new AlertDialog.Builder(this)
            .setIcon(aInfo.loadIcon(packageManager))
            .setMessage(getString(R.string.media_projection_dialog_text, appName))
            .setPositiveButton(R.string.media_projection_action_text, this)
            .setNegativeButton(android.R.string.cancel, this)
            .setView(R.layout.remember_permission_checkbox)
            .setOnCancelListener(this)
            .create();

    mDialog.create();

    ((CheckBox) mDialog.findViewById(R.id.remember)).setOnCheckedChangeListener(this);
    mDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

    mDialog.show();
  }
 public void publish(Context context) {
   mContext = context;
   ServiceManager.addService("batteryinfo", asBinder());
   mStats.setNumSpeedSteps(new PowerProfile(mContext).getNumSpeedSteps());
   mStats.setRadioScanningTimeout(
       mContext
               .getResources()
               .getInteger(com.android.internal.R.integer.config_radioScanningTimeout)
           * 1000L);
 }
 private void copy(CharSequence text) {
   try {
     IClipboard clip = IClipboard.Stub.asInterface(ServiceManager.getService("clipboard"));
     if (clip != null) {
       clip.setClipboardText(text);
     }
   } catch (android.os.RemoteException e) {
     Log.e(LOGTAG, "Copy failed", e);
   }
 }
 /**
  * Get an AccessibilityManager instance (create one if necessary).
  *
  * @hide
  */
 public static AccessibilityManager getInstance(Context context) {
   synchronized (sInstanceSync) {
     if (sInstance == null) {
       IBinder iBinder = ServiceManager.getService(Context.ACCESSIBILITY_SERVICE);
       IAccessibilityManager service = IAccessibilityManager.Stub.asInterface(iBinder);
       sInstance = new AccessibilityManager(context, service);
     }
   }
   return sInstance;
 }
 private int getCurrentDensity() {
   IWindowManager wm =
       IWindowManager.Stub.asInterface(ServiceManager.checkService(Context.WINDOW_SERVICE));
   try {
     return wm.getBaseDisplayDensity(Display.DEFAULT_DISPLAY);
   } catch (RemoteException e) {
     e.printStackTrace();
   }
   return DisplayMetrics.DENSITY_DEVICE;
 }
 /**
  * Get a handle to the default local Bluetooth adapter.
  *
  * <p>Currently Android only supports one Bluetooth adapter, but the API could be extended to
  * support more. This will always return the default adapter.
  *
  * @return the default local adapter, or null if Bluetooth is not supported on this hardware
  *     platform
  */
 public static synchronized BluetoothAdapter getDefaultAdapter() {
   if (sAdapter == null) {
     IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
     if (b != null) {
       IBluetooth service = IBluetooth.Stub.asInterface(b);
       sAdapter = new BluetoothAdapter(service);
     }
   }
   return sAdapter;
 }
  private void writeLcdDensityPreference(final Context context, final int density) {
    final IActivityManager am =
        ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
    final IWindowManager wm =
        IWindowManager.Stub.asInterface(ServiceManager.checkService(Context.WINDOW_SERVICE));
    AsyncTask<Void, Void, Void> task =
        new AsyncTask<Void, Void, Void>() {
          @Override
          protected void onPreExecute() {
            ProgressDialog dialog = new ProgressDialog(context);
            dialog.setMessage(getResources().getString(R.string.restarting_ui));
            dialog.setCancelable(false);
            dialog.setIndeterminate(true);
            dialog.show();
          }

          @Override
          protected Void doInBackground(Void... params) {
            // Give the user a second to see the dialog
            try {
              Thread.sleep(1000);
            } catch (InterruptedException e) {
              // Ignore
            }

            try {
              wm.setForcedDisplayDensity(Display.DEFAULT_DISPLAY, density);
            } catch (RemoteException e) {
              Log.e(TAG, "Failed to set density to " + density, e);
            }

            // Restart the UI
            try {
              am.restart();
            } catch (RemoteException e) {
              Log.e(TAG, "Failed to restart");
            }
            return null;
          }
        };
    task.execute();
  }
Пример #30
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
    mBackupManager =
        IBackupManager.Stub.asInterface(ServiceManager.getService(Context.BACKUP_SERVICE));

    addPreferencesFromResource(R.xml.development_prefs);

    mEnableAdb = (CheckBoxPreference) findPreference(ENABLE_ADB);
    mKeepScreenOn = (CheckBoxPreference) findPreference(KEEP_SCREEN_ON);
    mAllowMockLocation = (CheckBoxPreference) findPreference(ALLOW_MOCK_LOCATION);
    mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD);

    mStrictMode = (CheckBoxPreference) findPreference(STRICT_MODE_KEY);
    mPointerLocation = (CheckBoxPreference) findPreference(POINTER_LOCATION_KEY);
    mShowTouches = (CheckBoxPreference) findPreference(SHOW_TOUCHES_KEY);
    mShowScreenUpdates = (CheckBoxPreference) findPreference(SHOW_SCREEN_UPDATES_KEY);
    mShowCpuUsage = (CheckBoxPreference) findPreference(SHOW_CPU_USAGE_KEY);
    mForceHardwareUi = (CheckBoxPreference) findPreference(FORCE_HARDWARE_UI_KEY);
    mWindowAnimationScale = (ListPreference) findPreference(WINDOW_ANIMATION_SCALE_KEY);
    mWindowAnimationScale.setOnPreferenceChangeListener(this);
    mTransitionAnimationScale = (ListPreference) findPreference(TRANSITION_ANIMATION_SCALE_KEY);
    mTransitionAnimationScale.setOnPreferenceChangeListener(this);

    mImmediatelyDestroyActivities =
        (CheckBoxPreference) findPreference(IMMEDIATELY_DESTROY_ACTIVITIES_KEY);
    mAppProcessLimit = (ListPreference) findPreference(APP_PROCESS_LIMIT_KEY);
    mAppProcessLimit.setOnPreferenceChangeListener(this);

    mShowAllANRs = (CheckBoxPreference) findPreference(SHOW_ALL_ANRS_KEY);

    final Preference verifierDeviceIdentifier = findPreference(VERIFIER_DEVICE_IDENTIFIER);
    final PackageManager pm = getActivity().getPackageManager();
    final VerifierDeviceIdentity verifierIndentity = pm.getVerifierDeviceIdentity();
    if (verifierIndentity != null) {
      verifierDeviceIdentifier.setSummary(verifierIndentity.toString());
    }

    removeHdcpOptionsForProduction();
  }