blob: 79233cb354ef3434ce4162205d5c96a583ee1cdb [file] [log] [blame]
The Android Open Source Project9d9730a2009-03-03 19:32:37 -08001/*
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
17package com.android.stk;
18
Takanori Nakano48544352016-12-02 18:32:59 +090019import android.app.ActionBar;
Wink Savillee68857d2014-10-17 15:23:05 -070020import android.app.ListActivity;
21import android.content.Context;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080022import android.content.Intent;
23import android.os.Bundle;
Wink Savillee68857d2014-10-17 15:23:05 -070024import android.view.View;
25import android.view.KeyEvent;
arunvodduaa8d8c32022-06-27 16:26:07 +000026import android.view.WindowManager;
Wink Savillee68857d2014-10-17 15:23:05 -070027import android.widget.ImageView;
28import android.widget.ListView;
29import android.widget.TextView;
30import android.graphics.Bitmap;
31import android.graphics.BitmapFactory;
32
33import com.android.internal.telephony.cat.Item;
34import com.android.internal.telephony.cat.Menu;
35import com.android.internal.telephony.cat.CatLog;
Wink Savillee68857d2014-10-17 15:23:05 -070036
37import android.telephony.TelephonyManager;
38
39import java.util.ArrayList;
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080040
41/**
Wink Saville79085fc2009-06-09 10:27:23 -070042 * Launcher class. Serve as the app's MAIN activity, send an intent to the
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080043 * StkAppService and finish.
Wink Saville79085fc2009-06-09 10:27:23 -070044 *
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080045 */
Wink Savillee68857d2014-10-17 15:23:05 -070046public class StkLauncherActivity extends ListActivity {
47 private TextView mTitleTextView = null;
48 private ImageView mTitleIconView = null;
Yoshiaki Naka3a980db2019-10-30 17:11:33 +090049 private static final String LOG_TAG =
50 new Object(){}.getClass().getEnclosingClass().getSimpleName();
Wink Savillee68857d2014-10-17 15:23:05 -070051 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 Project9d9730a2009-03-03 19:32:37 -080058 @Override
Wink Savillee68857d2014-10-17 15:23:05 -070059 public void onCreate(Bundle icicle) {
60 super.onCreate(icicle);
arunvodduaa8d8c32022-06-27 16:26:07 +000061 getWindow().addSystemFlags(
62 WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
Wink Savillee68857d2014-10-17 15:23:05 -070063 CatLog.d(LOG_TAG, "onCreate+");
64 mContext = getBaseContext();
65 mTm = (TelephonyManager) mContext.getSystemService(
66 Context.TELEPHONY_SERVICE);
Takanori Nakano48544352016-12-02 18:32:59 +090067
68 ActionBar actionBar = getActionBar();
69 actionBar.setCustomView(R.layout.stk_title);
70 actionBar.setDisplayShowCustomEnabled(true);
71
Legler Wuaeefef52014-10-27 00:57:18 +080072 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 Savillee68857d2014-10-17 15:23:05 -070078 }
The Android Open Source Project9d9730a2009-03-03 19:32:37 -080079
Wink Savillee68857d2014-10-17 15:23:05 -070080 @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 Naka8b960fb2019-10-31 10:44:07 +090099 if (item.id >= 0 && item.id < simCount) {
Wink Savillee68857d2014-10-17 15:23:05 -0700100 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 Nakano89e5d462016-03-31 20:10:30 +0900169 StkAppService appService = StkAppService.getInstance();
Yoshiaki Naka7153ec52017-10-17 15:08:56 +0900170 if (appService == null) {
171 return 0;
172 }
173
174 String appName = mContext.getResources().getString(R.string.app_name);
Wink Savillee68857d2014-10-17 15:23:05 -0700175 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 Naka7153ec52017-10-17 15:08:56 +0900181 // Check if the card is inserted.
Wink Savillee68857d2014-10-17 15:23:05 -0700182 if (mTm.hasIccCard(i)) {
Yoshiaki Naka7153ec52017-10-17 15:08:56 +0900183 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 Nakanoc8054ba2016-08-15 19:18:16 +0900190 // 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 Naka7153ec52017-10-17 15:08:56 +0900200 mStkMenuList.add(item);
201 } else {
202 CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " does not have main menu.");
203 }
Wink Savillee68857d2014-10-17 15:23:05 -0700204 } else {
Yoshiaki Naka7153ec52017-10-17 15:08:56 +0900205 CatLog.d(LOG_TAG, "SIM #" + (i + 1) + " is not inserted.");
Wink Savillee68857d2014-10-17 15:23:05 -0700206 }
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 Savillee68857d2014-10-17 15:23:05 -0700221 private void launchSTKMainMenu(int slodId) {
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800222 Bundle args = new Bundle();
Wink Savillee68857d2014-10-17 15:23:05 -0700223 CatLog.d(LOG_TAG, "launchSTKMainMenu.");
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800224 args.putInt(StkAppService.OPCODE, StkAppService.OP_LAUNCH_APP);
Yoshiaki Naka8b960fb2019-10-31 10:44:07 +0900225 args.putInt(StkAppService.SLOT_ID, slodId);
Wink Savillee68857d2014-10-17 15:23:05 -0700226 startService(new Intent(this, StkAppService.class)
227 .putExtras(args));
The Android Open Source Project9d9730a2009-03-03 19:32:37 -0800228 }
229}