1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.stk; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.os.Bundle; 23 24 import com.android.internal.telephony.cat.CatLog; 25 26 import android.telephony.TelephonyManager; 27 28 import android.view.Gravity; 29 import android.view.WindowManager; 30 import android.widget.Toast; 31 32 /** 33 * Launcher class. Serve as the app's MAIN activity, send an intent to the 34 * StkAppService and finish. 35 * 36 */ 37 public class StkMain extends Activity { 38 private static final String LOG_TAG = 39 new Object(){}.getClass().getEnclosingClass().getSimpleName(); 40 private int mSingleSimId = -1; 41 private Context mContext = null; 42 private TelephonyManager mTm = null; 43 private static final String PACKAGE_NAME = "com.android.stk"; 44 private static final String STK_LAUNCHER_ACTIVITY_NAME = PACKAGE_NAME + ".StkLauncherActivity"; 45 46 @Override onCreate(Bundle icicle)47 public void onCreate(Bundle icicle) { 48 super.onCreate(icicle); 49 getWindow().addSystemFlags( 50 WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); 51 CatLog.d(LOG_TAG, "onCreate+"); 52 mContext = getBaseContext(); 53 mTm = (TelephonyManager) mContext.getSystemService( 54 Context.TELEPHONY_SERVICE); 55 //Check if needs to show the meun list. 56 if (isShowSTKListMenu()) { 57 Intent newIntent = new Intent(Intent.ACTION_VIEW); 58 newIntent.setClassName(PACKAGE_NAME, STK_LAUNCHER_ACTIVITY_NAME); 59 startActivity(newIntent); 60 } else { 61 //launch stk menu activity for the SIM. 62 if (mSingleSimId < 0) { 63 showTextToast(mContext, R.string.no_sim_card_inserted); 64 } else { 65 launchSTKMainMenu(mSingleSimId); 66 } 67 } 68 finish(); 69 } 70 isShowSTKListMenu()71 private boolean isShowSTKListMenu() { 72 int simCount = TelephonyManager.from(mContext).getSimCount(); 73 int simInsertedCount = 0; 74 int insertedSlotId = -1; 75 76 CatLog.d(LOG_TAG, "simCount: " + simCount); 77 for (int i = 0; i < simCount; i++) { 78 //Check if the card is inserted. 79 if (mTm.hasIccCard(i)) { 80 CatLog.d(LOG_TAG, "SIM " + i + " is inserted."); 81 mSingleSimId = i; 82 simInsertedCount++; 83 } else { 84 CatLog.d(LOG_TAG, "SIM " + i + " is not inserted."); 85 } 86 } 87 if (simInsertedCount > 1) { 88 return true; 89 } else { 90 //No card or only one card. 91 CatLog.d(LOG_TAG, "do not show stk list menu."); 92 return false; 93 } 94 } 95 launchSTKMainMenu(int slotId)96 private void launchSTKMainMenu(int slotId) { 97 Bundle args = new Bundle(); 98 CatLog.d(LOG_TAG, "launchSTKMainMenu."); 99 args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP); 100 args.putInt(StkAppService.SLOT_ID, slotId); 101 startService(new Intent(this, StkAppService.class) 102 .putExtras(args)); 103 } 104 showTextToast(Context context, int resId)105 private void showTextToast(Context context, int resId) { 106 Toast toast = Toast.makeText(context, resId, Toast.LENGTH_LONG); 107 toast.setGravity(Gravity.BOTTOM, 0, 0); 108 toast.show(); 109 } 110 } 111