@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);
           }
         });
   }
 }
 @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;
 }
 /**
  * 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());
   }
 }
 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;
 }
  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();
  }
Пример #6
0
 /**
  * Resumes a call in progress. Typically launched from the EmergencyCall button on various
  * lockscreens.
  *
  * @return true if we were able to tell InCallScreen to show.
  */
 public boolean resumeCall() {
   ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
   try {
     if (phone != null && phone.showCallScreen()) {
       return true;
     }
   } catch (RemoteException e) {
     // What can we do?
   }
   return false;
 }
  public void BackHomeSource() {
    ITvServiceServer tvService =
        ITvServiceServer.Stub.asInterface(ServiceManager.checkService(Context.TV_SERVICE));
    if (tvService == null) {
      // Log.w(TAG, "Unable to find ITvService interface.");
    } else {
      try {
        ITvServiceServerCommon commonService = tvService.getCommonManager();
        EN_INPUT_SOURCE_TYPE currentSource = commonService.GetCurrentInputSource();
        if (currentSource.equals(EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_STORAGE) == false) {
          commonService.SetInputSource(EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_STORAGE);
        }

        EN_INPUT_SOURCE_TYPE currentSource1 = commonService.GetCurrentInputSource();

        if (currentSource1.equals(EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_STORAGE)) {
          commonService.SetInputSource(EN_INPUT_SOURCE_TYPE.E_INPUT_SOURCE_ATV);

          try {

            VideoWindowType videoWindowType = new VideoWindowType();
            videoWindowType.x = getResources().getDimensionPixelSize(R.dimen.tv_x);
            videoWindowType.y = getResources().getDimensionPixelSize(R.dimen.tv_y);
            videoWindowType.width = getResources().getDimensionPixelSize(R.dimen.tv_width);
            videoWindowType.height = getResources().getDimensionPixelSize(R.dimen.tv_height);
            Log.d("shine", "x=" + videoWindowType.x);
            Log.d("shine", "y=" + videoWindowType.y);
            Log.d("shine", "w=" + videoWindowType.width);
            Log.d("shine", "h=" + videoWindowType.height);
            TvManager.getPictureManager().selectWindow(EnumScalerWindow.E_MAIN_WINDOW);
            TvManager.getPictureManager().setDisplayWindow(videoWindowType);

          } catch (TvCommonException e) {
            e.printStackTrace();
          }
          int channel = mTvService.getChannelManager().getCurrentChannelNumber();
          Log.w("shine", "channel=" + channel);
          if ((channel < 0) || (channel > 255)) {
            channel = 0;
          }
          mTvService
              .getChannelManager()
              .programSel(channel, EN_MEMBER_SERVICE_TYPE.E_SERVICETYPE_ATV);
        } else {
          setPipscale();
        }
      } catch (RemoteException e) {
        e.printStackTrace();
      }
    }
  }
  /**
   * Returns true if the intent is due to hitting the green send key (hardware call button:
   * KEYCODE_CALL) while in a call.
   *
   * @param intent the intent that launched this activity
   * @param recentCallsRequest true if the intent is requesting to view recent calls
   * @return true if the intent is due to hitting the green send key while in a call
   */
  private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) {
    // If there is a call in progress go to the call screen
    if (recentCallsRequest) {
      final boolean callKey = intent.getBooleanExtra("call_key", false);

      try {
        ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
        if (callKey && phone != null && phone.showCallScreen()) {
          return true;
        }
      } catch (RemoteException e) {
        Log.e(TAG, "Failed to handle send while in call", e);
      }
    }

    return false;
  }
  @Override
  public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
      case KeyEvent.KEYCODE_CALL:
        try {
          ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
          if (phone != null && !phone.isIdle()) {
            // Let the super class handle it
            break;
          }
        } catch (RemoteException re) {
          // Fall through and try to call the contact
        }

        callEntry(getListView().getSelectedItemPosition());
        return true;
    }
    return super.onKeyUp(keyCode, event);
  }
  private final synchronized void init() {
    char[] buffer = new char[1024];

    String newName = mRingerswitchName;
    int newState = mRingerswitchState;
    try {
      FileReader file = new FileReader(RINGER_SWITCH_STATE_PATH);
      int len = file.read(buffer, 0, 1024);
      newState = Integer.valueOf((new String(buffer, 0, len)).trim());

      file = new FileReader(RINGER_SWITCH_NAME_PATH);
      len = file.read(buffer, 0, 1024);
      newName = new String(buffer, 0, len).trim();

    } catch (FileNotFoundException e) {
      Log.w(TAG, "This kernel does not have ringer switch support");
      return;
    } catch (Exception e) {
      Log.e(TAG, "", e);
    }

    mAudioService =
        IAudioService.Stub.asInterface(ServiceManager.checkService(Context.AUDIO_SERVICE));
  }
Пример #11
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);
  }
  /**
   * 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() {
    boolean bluetoothOff;
    boolean radioOff;

    BroadcastReceiver br =
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            // We don't allow apps to cancel this, so ignore the result.
            broadcastDone();
          }
        };

    Log.i(TAG, "Sending shutdown broadcast...");

    // First send the high-level shut down broadcast.
    mBroadcastDone = false;
    mContext.sendOrderedBroadcast(
        new Intent(Intent.ACTION_SHUTDOWN), null, br, mHandler, 0, null, null);

    final long endTime = System.currentTimeMillis() + MAX_BROADCAST_TIME;
    synchronized (mBroadcastDoneSync) {
      while (!mBroadcastDone) {
        long delay = endTime - System.currentTimeMillis();
        if (delay <= 0) {
          Log.w(TAG, "Shutdown broadcast timed out");
          break;
        }
        try {
          mBroadcastDoneSync.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) {
      }
    }

    final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
    final IBluetooth bluetooth =
        IBluetooth.Stub.asInterface(
            ServiceManager.checkService(BluetoothAdapter.BLUETOOTH_SERVICE));

    final IMountService mount =
        IMountService.Stub.asInterface(ServiceManager.checkService("mount"));

    try {
      bluetoothOff =
          bluetooth == null || bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
      if (!bluetoothOff) {
        Log.w(TAG, "Disabling Bluetooth...");
        bluetooth.disable(false); // disable but don't persist new state
      }
    } catch (RemoteException ex) {
      Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
      bluetoothOff = true;
    }

    try {
      radioOff = phone == null || !phone.isRadioOn();
      if (!radioOff) {
        Log.w(TAG, "Turning off radio...");
        phone.setRadio(false);
      }
    } catch (RemoteException ex) {
      Log.e(TAG, "RemoteException during radio shutdown", ex);
      radioOff = true;
    }

    Log.i(TAG, "Waiting for Bluetooth and Radio...");

    // Wait a max of 32 seconds for clean shutdown
    for (int i = 0; i < MAX_NUM_PHONE_STATE_READS; i++) {
      if (!bluetoothOff) {
        try {
          bluetoothOff = bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF;
        } catch (RemoteException ex) {
          Log.e(TAG, "RemoteException during bluetooth shutdown", ex);
          bluetoothOff = true;
        }
      }
      if (!radioOff) {
        try {
          radioOff = !phone.isRadioOn();
        } catch (RemoteException ex) {
          Log.e(TAG, "RemoteException during radio shutdown", ex);
          radioOff = true;
        }
      }
      if (radioOff && bluetoothOff) {
        Log.i(TAG, "Radio and Bluetooth shutdown complete.");
        break;
      }
      SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC);
    }

    // Shutdown MountService to ensure media is in a safe state
    try {
      if (mount != null) {
        mount.shutdown();
      } else {
        Log.w(TAG, "MountService unavailable for shutdown");
      }
    } catch (Exception e) {
      Log.e(TAG, "Exception during MountService shutdown", e);
    }

    // shutdown power
    Log.i(TAG, "Performing low-level shutdown...");
    Power.shutdown();
  }
 @Override
 protected Void doInBackground(Void... args) {
   Log.i(TAG, "[ShowSimCardStorageInfoTask]: doInBackground_beg");
   sSurplugMap.clear();
   List<SimInfoRecord> simInfos =
       getSortedInsertedSimInfoList(SimInfoManager.getInsertedSimInfoList(mContext));
   Log.i(TAG, "[ShowSimCardStorageInfoTask]: simInfos.size = " + simInfos.size());
   if (!mIsCancelled && (simInfos != null) && simInfos.size() > 0) {
     StringBuilder build = new StringBuilder();
     int simId = 0;
     for (SimInfoRecord simInfo : simInfos) {
       if (simId > 0) {
         build.append("\n\n");
       }
       simId++;
       int[] storageInfos = null;
       Log.i(
           TAG,
           "[ShowSimCardStorageInfoTask] simName = "
               + simInfo.mDisplayName
               + "; simSlot = "
               + simInfo.mSimSlotId
               + "; simId = "
               + simInfo.mSimInfoId);
       build.append(simInfo.mDisplayName);
       build.append(":\n");
       try {
         ITelephonyEx phoneEx =
             ITelephonyEx.Stub.asInterface(ServiceManager.checkService("phoneEx"));
         if (!mIsCancelled && phoneEx != null) {
           storageInfos = phoneEx.getAdnStorageInfo(simInfo.mSimSlotId);
           if (storageInfos == null) {
             mIsException = true;
             Log.i(TAG, " storageInfos is null");
             return null;
           }
           Log.i(TAG, "[ShowSimCardStorageInfoTask] infos: " + storageInfos.toString());
         } else {
           Log.i(TAG, "[ShowSimCardStorageInfoTask]: phone = null");
           mIsException = true;
           return null;
         }
       } catch (RemoteException ex) {
         Log.i(TAG, "[ShowSimCardStorageInfoTask]_exception: " + ex);
         mIsException = true;
         return null;
       }
       Log.i(
           TAG,
           "slotId:"
               + simInfo.mSimSlotId
               + "||storage:"
               + (storageInfos == null ? "NULL" : storageInfos[1])
               + "||used:"
               + (storageInfos == null ? "NULL" : storageInfos[0]));
       if (storageInfos != null && storageInfos[1] > 0) {
         sSurplugMap.put(simInfo.mSimSlotId, storageInfos[1] - storageInfos[0]);
       }
       build.append(
           mContext
               .getResources()
               .getString(R.string.dlg_simstorage_content, storageInfos[1], storageInfos[0]));
       if (mIsCancelled) {
         return null;
       }
     }
     mDlgContent = build.toString();
   }
   Log.i(TAG, "[ShowSimCardStorageInfoTask]: doInBackground_end");
   return null;
 }