The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 19 | import android.app.ActionBar; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 20 | import android.app.ListActivity; |
| 21 | import android.content.Context; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.os.Bundle; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 24 | import android.view.View; |
| 25 | import android.view.KeyEvent; |
arunvoddu | aa8d8c3 | 2022-06-27 16:26:07 +0000 | [diff] [blame] | 26 | import android.view.WindowManager; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 27 | import android.widget.ImageView; |
| 28 | import android.widget.ListView; |
| 29 | import android.widget.TextView; |
| 30 | import android.graphics.Bitmap; |
| 31 | import android.graphics.BitmapFactory; |
| 32 | |
| 33 | import com.android.internal.telephony.cat.Item; |
| 34 | import com.android.internal.telephony.cat.Menu; |
| 35 | import com.android.internal.telephony.cat.CatLog; |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 36 | |
| 37 | import android.telephony.TelephonyManager; |
| 38 | |
| 39 | import java.util.ArrayList; |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 42 | * Launcher class. Serve as the app's MAIN activity, send an intent to the |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 43 | * StkAppService and finish. |
Wink Saville | 79085fc | 2009-06-09 10:27:23 -0700 | [diff] [blame] | 44 | * |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 45 | */ |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 46 | public class StkLauncherActivity extends ListActivity { |
| 47 | private TextView mTitleTextView = null; |
| 48 | private ImageView mTitleIconView = null; |
Yoshiaki Naka | 3a980db | 2019-10-30 17:11:33 +0900 | [diff] [blame] | 49 | private static final String LOG_TAG = |
| 50 | new Object(){}.getClass().getEnclosingClass().getSimpleName(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 51 | private ArrayList<Item> mStkMenuList = null; |
| 52 | private int mSingleSimId = -1; |
| 53 | private Context mContext = null; |
| 54 | private TelephonyManager mTm = null; |
| 55 | private Bitmap mBitMap = null; |
| 56 | private boolean mAcceptUsersInput = true; |
| 57 | |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 58 | @Override |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 59 | public void onCreate(Bundle icicle) { |
| 60 | super.onCreate(icicle); |
arunvoddu | aa8d8c3 | 2022-06-27 16:26:07 +0000 | [diff] [blame] | 61 | getWindow().addSystemFlags( |
| 62 | WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 63 | CatLog.d(LOG_TAG, "onCreate+"); |
| 64 | mContext = getBaseContext(); |
| 65 | mTm = (TelephonyManager) mContext.getSystemService( |
| 66 | Context.TELEPHONY_SERVICE); |
Takanori Nakano | 4854435 | 2016-12-02 18:32:59 +0900 | [diff] [blame] | 67 | |
| 68 | ActionBar actionBar = getActionBar(); |
| 69 | actionBar.setCustomView(R.layout.stk_title); |
| 70 | actionBar.setDisplayShowCustomEnabled(true); |
| 71 | |
Legler Wu | aeefef5 | 2014-10-27 00:57:18 +0800 | [diff] [blame] | 72 | setContentView(R.layout.stk_menu_list); |
| 73 | mTitleTextView = (TextView) findViewById(R.id.title_text); |
| 74 | mTitleIconView = (ImageView) findViewById(R.id.title_icon); |
| 75 | mTitleTextView.setText(R.string.app_name); |
| 76 | mBitMap = BitmapFactory.decodeResource(getResources(), |
| 77 | R.drawable.ic_launcher_sim_toolkit); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 78 | } |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 79 | |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 80 | @Override |
| 81 | protected void onNewIntent(Intent intent) { |
| 82 | super.onNewIntent(intent); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | protected void onListItemClick(ListView l, View v, int position, long id) { |
| 87 | super.onListItemClick(l, v, position, id); |
| 88 | if (!mAcceptUsersInput) { |
| 89 | CatLog.d(LOG_TAG, "mAcceptUsersInput:false"); |
| 90 | return; |
| 91 | } |
| 92 | int simCount = TelephonyManager.from(mContext).getSimCount(); |
| 93 | Item item = getSelectedItem(position); |
| 94 | if (item == null) { |
| 95 | CatLog.d(LOG_TAG, "Item is null"); |
| 96 | return; |
| 97 | } |
| 98 | CatLog.d(LOG_TAG, "launch stk menu id: " + item.id); |
Yoshiaki Naka | 8b960fb | 2019-10-31 10:44:07 +0900 | [diff] [blame] | 99 | if (item.id >= 0 && item.id < simCount) { |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 100 | mAcceptUsersInput = false; |
| 101 | launchSTKMainMenu(item.id); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 107 | CatLog.d(LOG_TAG, "mAcceptUsersInput: " + mAcceptUsersInput); |
| 108 | if (!mAcceptUsersInput) { |
| 109 | return true; |
| 110 | } |
| 111 | switch (keyCode) { |
| 112 | case KeyEvent.KEYCODE_BACK: |
| 113 | CatLog.d(LOG_TAG, "KEYCODE_BACK."); |
| 114 | mAcceptUsersInput = false; |
| 115 | finish(); |
| 116 | return true; |
| 117 | } |
| 118 | return super.onKeyDown(keyCode, event); |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void onResume() { |
| 123 | super.onResume(); |
| 124 | CatLog.d(LOG_TAG, "onResume"); |
| 125 | mAcceptUsersInput = true; |
| 126 | int itemSize = addStkMenuListItems(); |
| 127 | if (itemSize == 0) { |
| 128 | CatLog.d(LOG_TAG, "item size = 0 so finish."); |
| 129 | finish(); |
| 130 | } else if (itemSize == 1) { |
| 131 | launchSTKMainMenu(mSingleSimId); |
| 132 | finish(); |
| 133 | } else { |
| 134 | CatLog.d(LOG_TAG, "resume to show multiple stk list."); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void onPause() { |
| 140 | super.onPause(); |
| 141 | CatLog.d(LOG_TAG, "onPause"); |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public void onDestroy() { |
| 146 | super.onDestroy(); |
| 147 | CatLog.d(LOG_TAG, "onDestroy"); |
| 148 | } |
| 149 | |
| 150 | private Item getSelectedItem(int position) { |
| 151 | Item item = null; |
| 152 | if (mStkMenuList != null) { |
| 153 | try { |
| 154 | item = mStkMenuList.get(position); |
| 155 | } catch (IndexOutOfBoundsException e) { |
| 156 | if (StkApp.DBG) { |
| 157 | CatLog.d(LOG_TAG, "IOOBE Invalid menu"); |
| 158 | } |
| 159 | } catch (NullPointerException e) { |
| 160 | if (StkApp.DBG) { |
| 161 | CatLog.d(LOG_TAG, "NPE Invalid menu"); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | return item; |
| 166 | } |
| 167 | |
| 168 | private int addStkMenuListItems() { |
Takanori Nakano | 89e5d46 | 2016-03-31 20:10:30 +0900 | [diff] [blame] | 169 | StkAppService appService = StkAppService.getInstance(); |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 170 | if (appService == null) { |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | String appName = mContext.getResources().getString(R.string.app_name); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 175 | String stkItemName = null; |
| 176 | int simCount = TelephonyManager.from(mContext).getSimCount(); |
| 177 | mStkMenuList = new ArrayList<Item>(); |
| 178 | |
| 179 | CatLog.d(LOG_TAG, "simCount: " + simCount); |
| 180 | for (int i = 0; i < simCount; i++) { |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 181 | // Check if the card is inserted. |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 182 | if (mTm.hasIccCard(i)) { |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 183 | Menu menu = appService.getMainMenu(i); |
| 184 | // Check if the card has a main menu. |
| 185 | if (menu != null) { |
| 186 | CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " is add to menu."); |
| 187 | mSingleSimId = i; |
| 188 | stkItemName = new StringBuilder(menu.title == null ? appName : menu.title) |
| 189 | .append(" ").append(Integer.toString(i + 1)).toString(); |
Takanori Nakano | c8054ba | 2016-08-15 19:18:16 +0900 | [diff] [blame] | 190 | // Display the default application icon if there is no icon specified by SET-UP |
| 191 | // MENU command nor preset. |
| 192 | Bitmap icon = mBitMap; |
| 193 | if (menu.titleIcon != null) { |
| 194 | icon = menu.titleIcon; |
| 195 | if (menu.titleIconSelfExplanatory) { |
| 196 | stkItemName = null; |
| 197 | } |
| 198 | } |
| 199 | Item item = new Item(i, stkItemName, icon); |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 200 | mStkMenuList.add(item); |
| 201 | } else { |
| 202 | CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " does not have main menu."); |
| 203 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 204 | } else { |
Yoshiaki Naka | 7153ec5 | 2017-10-17 15:08:56 +0900 | [diff] [blame] | 205 | CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " is not inserted."); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | if (mStkMenuList != null && mStkMenuList.size() > 0) { |
| 209 | if (mStkMenuList.size() > 1) { |
| 210 | StkMenuAdapter adapter = new StkMenuAdapter(this, |
| 211 | mStkMenuList, false); |
| 212 | // Bind menu list to the new adapter. |
| 213 | this.setListAdapter(adapter); |
| 214 | } |
| 215 | return mStkMenuList.size(); |
| 216 | } else { |
| 217 | CatLog.d(LOG_TAG, "No stk menu item add."); |
| 218 | return 0; |
| 219 | } |
| 220 | } |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 221 | private void launchSTKMainMenu(int slodId) { |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 222 | Bundle args = new Bundle(); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 223 | CatLog.d(LOG_TAG, "launchSTKMainMenu."); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 224 | args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP); |
Yoshiaki Naka | 8b960fb | 2019-10-31 10:44:07 +0900 | [diff] [blame] | 225 | args.putInt(StkAppService.SLOT_ID, slodId); |
Wink Saville | e68857d | 2014-10-17 15:23:05 -0700 | [diff] [blame] | 226 | startService(new Intent(this, StkAppService.class) |
| 227 | .putExtras(args)); |
The Android Open Source Project | 9d9730a | 2009-03-03 19:32:37 -0800 | [diff] [blame] | 228 | } |
| 229 | } |