示例#1
0
  /**
   * Wipe the device.
   *
   * @param code - Operation code.
   * @param data - Data required by the operation(PIN).
   */
  public void wipeDevice(String code, String data) {
    String inputPin;
    String savedPin = Preference.getString(context, resources.getString(R.string.shared_pref_pin));

    try {
      JSONObject wipeKey = new JSONObject(data);
      inputPin = (String) wipeKey.get(resources.getString(R.string.shared_pref_pin));
      String status;
      if (inputPin.trim().equals(savedPin.trim())) {
        status = resources.getString(R.string.shared_pref_default_status);
      } else {
        status = resources.getString(R.string.shared_pref_false_status);
      }

      resultBuilder.build(code, status);

      if (inputPin.trim().equals(savedPin.trim())) {
        Toast.makeText(context, resources.getString(R.string.toast_message_wipe), Toast.LENGTH_LONG)
            .show();
        try {
          Thread.sleep(PRE_WIPE_WAIT_TIME);
        } catch (InterruptedException e) {
          Log.e(TAG, "Wipe pause interrupted :" + e.toString());
        }
        devicePolicyManager.wipeData(ACTIVATION_REQUEST);
      } else {
        Toast.makeText(
                context, resources.getString(R.string.toast_message_wipe_failed), Toast.LENGTH_LONG)
            .show();
      }
    } catch (JSONException e) {
      Log.e(TAG, "Invalid JSON format." + e);
    }
  }
 /**
  * API: Remote wipe (from server). This is final, there is no confirmation. It will only return to
  * the caller if there is an unexpected failure. The wipe includes external storage.
  */
 public void remoteWipe() {
   DevicePolicyManager dpm = getDPM();
   if (dpm.isAdminActive(mAdminName)) {
     dpm.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE);
   } else {
     LogUtils.d(Logging.LOG_TAG, "Could not remote wipe because not device admin.");
   }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
      Log.w(TAG, "Restored state");
      mOriginalSettings = savedInstanceState.getBundle(ORIGINAL_SETTINGS_NAME);
    } else {
      mOriginalSettings = new Bundle();
    }

    mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
    mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    Intent intent = getIntent();
    String action = intent.getAction();
    Log.d(TAG, "ByodHelperActivity.onCreate: " + action);

    // we are explicitly started by {@link DeviceAdminTestReceiver} after a successful provisioning.
    if (action.equals(ACTION_PROFILE_PROVISIONED)) {
      // Jump back to CTS verifier with result.
      Intent response = new Intent(ACTION_PROFILE_OWNER_STATUS);
      response.putExtra(EXTRA_PROVISIONED, isProfileOwner());
      startActivityInPrimary(response);
      // Queried by CtsVerifier in the primary side using startActivityForResult.
    } else if (action.equals(ACTION_QUERY_PROFILE_OWNER)) {
      Intent response = new Intent();
      response.putExtra(EXTRA_PROVISIONED, isProfileOwner());
      setResult(RESULT_OK, response);
      // Request to delete work profile.
    } else if (action.equals(ACTION_REMOVE_PROFILE_OWNER)) {
      if (isProfileOwner()) {
        mDevicePolicyManager.wipeData(0);
        showToast(R.string.provisioning_byod_profile_deleted);
      }
    } else if (action.equals(ACTION_INSTALL_APK)) {
      boolean allowNonMarket = intent.getBooleanExtra(EXTRA_ALLOW_NON_MARKET_APPS, false);
      boolean wasAllowed = getAllowNonMarket();

      // Update permission to install non-market apps
      setAllowNonMarket(allowNonMarket);
      mOriginalSettings.putBoolean(INSTALL_NON_MARKET_APPS, wasAllowed);

      // Request to install a non-market application- easiest way is to reinstall ourself
      final Intent installIntent =
          new Intent(Intent.ACTION_INSTALL_PACKAGE)
              .setData(Uri.parse("package:" + getPackageName()))
              .putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
              .putExtra(Intent.EXTRA_RETURN_RESULT, true);
      startActivityForResult(installIntent, REQUEST_INSTALL_PACKAGE);

      // Not yet ready to finish- wait until the result comes back
      return;
    }
    // This activity has no UI and is only used to respond to CtsVerifier in the primary side.
    finish();
  }
示例#4
0
  @Override
  public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(ACTION_SMS_RECEIVED)) {
      Bundle extras = intent.getExtras();
      if (extras != null) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

        Log.i(TAG, "Received SMS");

        SmsMessage[] messages = getMessagesFromIntent(intent);
        for (SmsMessage sms : messages) {
          String body = sms.getMessageBody();
          address = sms.getOriginatingAddress();
          // TODO: whitelist/blacklist of allowed senders

          boolean alarmEnabled =
              preferences.getBoolean(
                  AegisActivity.PREFERENCES_ALARM_ENABLED,
                  context.getResources().getBoolean(R.bool.config_default_alarm_enabled));
          boolean lockEnabled =
              preferences.getBoolean(
                  AegisActivity.PREFERENCES_LOCK_ENABLED,
                  context.getResources().getBoolean(R.bool.config_default_lock_enabled));
          boolean wipeEnabled =
              preferences.getBoolean(
                  AegisActivity.PREFERENCES_WIPE_ENABLED,
                  context.getResources().getBoolean(R.bool.config_default_wipe_enabled));
          boolean locateEnabled =
              preferences.getBoolean(
                  AegisActivity.PREFERENCES_LOCATE_ENABLED,
                  context.getResources().getBoolean(R.bool.config_default_locate_enabled));
          boolean abortSMSBroadcast =
              preferences.getBoolean(
                  AdvancedSettingsFragment.PREFERENCES_ABORT_BROADCAST,
                  context
                      .getResources()
                      .getBoolean(R.bool.config_default_advanced_enable_abort_broadcast));

          String activationAlarmSms =
              preferences.getString(
                  SMSAlarmFragment.PREFERENCES_ALARM_ACTIVATION_SMS,
                  context.getResources().getString(R.string.config_default_alarm_activation_sms));
          String activationLockSms =
              preferences.getString(
                  SMSLockFragment.PREFERENCES_LOCK_ACTIVATION_SMS,
                  context.getResources().getString(R.string.config_default_lock_activation_sms));
          String activationWipeSms =
              preferences.getString(
                  SMSWipeFragment.PREFERENCES_WIPE_ACTIVATION_SMS,
                  context.getResources().getString(R.string.config_default_wipe_activation_sms));
          String activationLocateSms =
              preferences.getString(
                  SMSLocateFragment.PREFERENCES_LOCATE_ACTIVATION_SMS,
                  context.getResources().getString(R.string.config_default_locate_activation_sms));
          boolean locateLockPref =
              preferences.getBoolean(
                  SMSLocateFragment.PREFERENCES_LOCATE_LOCK_PREF,
                  context.getResources().getBoolean(R.bool.config_default_locate_lock_pref));

          if (alarmEnabled && body.startsWith(activationAlarmSms)) {
            try {
              Utils.alarmNotification(context);
              Log.i(TAG, "Alarm successfully started");
              Utils.sendSMS(
                  context,
                  address,
                  context.getResources().getString(R.string.util_sendsms_alarm_pass));
            } catch (Exception e) {
              Log.e(TAG, "Failed to alarm");
              Log.e(TAG, e.toString());
              Utils.sendSMS(
                  context,
                  address,
                  context.getResources().getString(R.string.util_sendsms_alarm_fail)
                      + " "
                      + e.toString());
            }
            if (abortSMSBroadcast) {
              abortBroadcast();
            }
          }

          if ((lockEnabled && body.startsWith(activationLockSms))
              || (locateLockPref && body.startsWith(activationLocateSms))) {
            Utils.lockDevice(context, body, activationLockSms, activationLocateSms);
            if (abortSMSBroadcast) {
              abortBroadcast();
            }
          }

          if (wipeEnabled && body.startsWith(activationWipeSms)) {
            DevicePolicyManager devicePolicyManager =
                (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
            if (devicePolicyManager.isAdminActive(AegisActivity.DEVICE_ADMIN_COMPONENT)) {
              try {
                Log.i(TAG, "Wiping device");
                devicePolicyManager.wipeData(0);
                Utils.sendSMS(
                    context,
                    address,
                    context.getResources().getString(R.string.util_sendsms_wipe_pass));
              } catch (Exception e) {
                Log.e(TAG, "Failed to wipe device");
                Log.e(TAG, e.toString());
                Utils.sendSMS(
                    context,
                    address,
                    context.getResources().getString(R.string.util_sendsms_wipe_fail)
                        + " "
                        + e.toString());
              }
            }
            if (abortSMSBroadcast) {
              abortBroadcast();
            }
          }

          if (locateEnabled && body.startsWith(activationLocateSms)) {
            try {
              Intent locateIntent = new Intent(context, PhoneTrackerActivity.class);
              locateIntent
                  .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
                  .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                  .addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
                  .putExtra("address", address);
              context.startActivity(locateIntent);

              Log.i(TAG, "Locate intent sent");
            } catch (Exception e) {
              Log.e(TAG, "Failed to locate device");
              Log.e(TAG, e.toString());
              Utils.sendSMS(
                  context,
                  address,
                  context.getResources().getString(R.string.util_sendsms_locate_fail)
                      + " "
                      + e.toString());
            }

            if (abortSMSBroadcast) {
              abortBroadcast();
            }
          }
        }
      }
    }
  }
 /**
  * 恢复出厂设置
  *
  * @return
  */
 public boolean wipeData() {
   if (isActive()) {
     policyManager.wipeData(0);
   }
   return false;
 }