blob: 2497348aee1b16a5e7f277d76b2b24aa7f032a58 [file] [log] [blame]
SongFerngWang154bc962018-10-23 16:47:40 +08001/*
2 * Copyright (C) 2018 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.phone;
18
19import android.content.Context;
20import android.content.res.XmlResourceParser;
21import android.telephony.TelephonyManager;
22import android.text.TextUtils;
23import android.util.Log;
24
25import org.xmlpull.v1.XmlPullParser;
26import org.xmlpull.v1.XmlPullParserException;
27
28import java.io.IOException;
29import java.util.ArrayList;
30import java.util.HashMap;
31import java.util.Map;
32import java.util.Vector;
33import java.util.regex.Matcher;
34import java.util.regex.Pattern;
35
36/**
37 * CarrierXmlParser is a xml parser. It parses the carrier's ussd format from carrier_ss_string.xml.
38 * The carrier_ss_string.xml defines carrier's ussd structure and meaning in res/xml folder.
39 * Some carrier has specific ussd structure ,developer can add new xml and xml is named
40 * carrier_ss_string_carrierId.xml. The carrierId is a number and is defined in
41 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a>
42 * For example: carrier_ss_string_850.xml
43 * <p>
44 * How do use CarrierXmlParser?
45 * For example:
46 * @see CallForwardEditPreference
47 * TelephonyManager telephonyManager = new TelephonyManager(getContext(),phone.getSubId());
48 * CarrierXmlParser = new CarrierXmlParser(getContext(), telephonyManager.getSimCarrierId());
49 *
50 * //make a ussd command
51 * String newUssdCommand = mCarrierXmlParser.getFeature(
52 * CarrierXmlParser.FEATURE_CALL_FORWARDING).makeCommand(inputAction, inputCfInfo);
53 * //analyze ussd result
54 * HashMap<String, String> analysisResult = mCarrierXmlParser.getFeature(
55 * CarrierXmlParser.FEATURE_CALL_FORWARDING)
56 * .getResponseSet(mSsAction, response.toString());
57 */
58public class CarrierXmlParser {
59 public static final String LOG_TAG = "CarrierXmlParser";
60 private static final boolean DEBUG = true;
61
62 private static final String STAR_SIGN = "*";
63 private static final String POUND_SIGN = "#";
64
65 private static final String TAG_SIGN = "tag_";
66
67 // To define feature's item name in xml
68 public static final String FEATURE_CALL_FORWARDING = "callforwarding";
69 public static final String FEATURE_CALLER_ID = "callerid";
70
71 // COMMAND_NAME is xml's command name.
72 public static final String TAG_COMMAND_NAME_QUERY = "query";
73 public static final String TAG_COMMAND_NAME_ACTIVATE = "activate";
74 public static final String TAG_COMMAND_NAME_DEACTIVATE = "deactivate";
75
76 // To define string level in xml.
77 // level 1
78 private static final String TAG_FEATURE = "feature";
79 private static final String TAG_REGULAR_PARSER = "regular_parser";
80 // level 2
81 private static final String TAG_COMMAND = "command";
82 // level 3
83 private static final String TAG_SERVICE_CODE = "service_code";
84 private static final String TAG_ACTION_CODE = "action_code";
85 private static final String TAG_PARAMETER = "parameter";
86 private static final String TAG_RESPONSE_FORMAT = "response_format";
87 private static final String TAG_COMMAND_RESULT = "command_result";
88 // level 4
89 private static final String TAG_ENTRY = "entry";
90
91 private static final String ATTR_NAME = "name";
92 private static final String ATTR_PARAMETER_NUM = "number";
93 private static final String ATTR_POSITION = "position";
94 private static final String ATTR_RESULT_KEY = "key";
95 private static final String ATTR_DEFINITION_KEY = "definition";
96
97 HashMap<String, SsFeature> mFeatureMaps;
98 private static String sParserFormat = "";
99
100 // TAG_ENTRY_NUMBER and TAG_ENTRY_TIME is xml's entry value.
101 // This is mapping user's input value. For example: number,time ...
102 // When UI makes command ,it will map the value and insert this value at position location.
103 // How to use it?
104 // The UI calls CarrierXmlParser's makeCommand function and inputs the hashmap which
105 // includes tag_name and user's input value.
106 // For example: User calls CarrierXmlParser's makeCommand in call forwarding , and inputs
107 // the hashmap {<TAG_ENTRY_NUMBER,0123456789>,<TAG_ENTRY_TIME,20>}
108 // If developer wants to add new one, xml string should the same as hashmap's name.
109 public static final String TAG_ENTRY_NUMBER = "tag_number";
110 public static final String TAG_ENTRY_TIME = "tag_time";
111
112 // "response_format" key
113 // The key of "response_format" should define as below in xml.
114 // The UI will use it to define value from the response command
115 // and use the data show the screen.
116 public static final String TAG_RESPONSE_STATUS = "status_code";
117 public static final String TAG_RESPONSE_STATUS_ERROR = "RESPONSE_ERROR";
118 public static final String TAG_RESPONSE_NUMBER = "number";
119 public static final String TAG_RESPONSE_TIME = "time";
120
121 // This is the definition for the entry's key in response_format.
122 // Xml's COMMAND_RESULT_DEFINITION should same as below.
123 public static final String TAG_COMMAND_RESULT_DEFINITION_ACTIVATE = "activate";
124 public static final String TAG_COMMAND_RESULT_DEFINITION_DEACTIVATE = "deactivate";
125 public static final String TAG_COMMAND_RESULT_DEFINITION_UNREGISTER = "unregister";
126 public static final String TAG_COMMAND_RESULT_DEFINITION_OK = "ok";
127 public static final String TAG_COMMAND_RESULT_DEFINITION_FAIL = "fail";
128
129 /**
130 * UssdParser is a string parser. It parses the USSD response message.
131 */
132 public static class UssdParser {
133 private Vector<String> mParserStr = new Vector<String>();
134 private Pattern mPatternSuppServiceResponse;
135
136 public UssdParser(String inputParserFormat) {
137 mPatternSuppServiceResponse = Pattern.compile(inputParserFormat);
138 }
139
140 /**
141 * This function is a parser and analyzes the USSD responses message.
142 *
143 * @param responseString The USSD responses message.
144 */
145 public void newFromResponseString(String responseString) {
146 Matcher m;
147 m = mPatternSuppServiceResponse.matcher(responseString);
148 if (m.matches()) {
149 mParserStr.clear();
150 int groupSize = m.groupCount();
151 for (int i = 0; i <= groupSize; i++) {
152 if (!TextUtils.isEmpty(m.group(i))) {
153 mParserStr.add(m.group(i));
154 }
155 }
156 }
157 }
158
159 /**
160 * To get the UssdParser result.
161 */
162 public Vector<String> getResult() {
163 return mParserStr;
164 }
165 }
166
167 /**
168 * CarrierXmlParser parses command from xml and saves in SsEntry class.
169 */
170 public static class SsEntry {
171 public enum SSAction {
172 UNKNOWN,
173 QUERY,
174 UPDATE_ACTIVATE,
175 UPDATE_DEACTIVATE
176 }
177
178 public String serviceCode;
179 public SSAction ssAction = SSAction.UNKNOWN;
180 public String actionCode;
181 public HashMap<Integer, String> commandParameter = new HashMap<Integer, String>();
182 public HashMap<Integer, String> responseFormat = new HashMap<Integer, String>();
183
184 public SsEntry(String action) {
185 if (action.equals(TAG_COMMAND_NAME_QUERY)) {
186 ssAction = SSAction.QUERY;
187 } else if (action.equals(TAG_COMMAND_NAME_ACTIVATE)) {
188 ssAction = SSAction.UPDATE_ACTIVATE;
189 } else if (action.equals(TAG_COMMAND_NAME_DEACTIVATE)) {
190 ssAction = SSAction.UPDATE_DEACTIVATE;
191 }
192 }
193
194 @Override
195 public String toString() {
196 return "SsEntry serviceCode:" + serviceCode
197 + ", ssAction:" + ssAction
198 + ", actionCode:" + actionCode
199 + ", commandParameter:" + commandParameter.toString()
200 + ", responseFormat:" + responseFormat.toString();
201 }
202
203 /**
204 * To get the caller id command by xml's structure.
205 */
206 public String getCommandStructure() {
207 String result = actionCode + serviceCode;
208 int mapSize = commandParameter.size();
209 int parameterIndex = 0;
210 while (parameterIndex < mapSize) {
211 parameterIndex++;
212 if (commandParameter.containsKey(parameterIndex)) {
213 if (commandParameter.get(parameterIndex) != null) {
214 result = result + STAR_SIGN + commandParameter.get(parameterIndex);
215 }
216 }
217 }
218 result = result + POUND_SIGN;
219 Log.d(LOG_TAG, "getCommandStructure result:" + result);
220 return result;
221 }
222
223 /**
224 * To make ussd command by xml's structure.
225 *
226 * @param inputInformationSet This is a map which includes parameters from UI.
227 * The name of map is mapping parameter's key of entry in xml.
228 */
229 public String makeCommand(Map<String, String> inputInformationSet) {
230 String result = actionCode + serviceCode;
231 int mapSize = commandParameter.size();
232 int parameterIndex = 0;
233 int counter = 1;
234 Map<String, String> informationSet = inputInformationSet;
235 while (parameterIndex < mapSize) {
236 if (commandParameter.containsKey(counter)) {
237 String getInputValue = "";
238 // need to handle tag_XXXX
239 if (informationSet != null && informationSet.size() > 0
240 && informationSet.containsKey(commandParameter.get(counter))) {
241 getInputValue = informationSet.get(commandParameter.get(counter));
242 }
243 if (TextUtils.isEmpty(getInputValue)) {
244 result = result + STAR_SIGN + commandParameter.get(counter);
245 } else {
246 result = result + STAR_SIGN + informationSet.get(
247 commandParameter.get(counter));
248 }
249 parameterIndex++;
250 } else {
251 result = result + STAR_SIGN;
252 }
253 counter++;
254 }
255 result = result + POUND_SIGN;
256 return result;
257 }
258
259 /**
260 * To parse the specific key and value from response message.
261 *
262 * @param inputResponse This is a ussd response message from network.
263 * @param responseDefine This is the definition for "command_result" in xml.
264 */
265 public HashMap<String, String> getResponseSet(String inputResponse,
266 HashMap<String, ArrayList<SsResultEntry>> responseDefine) {
267 HashMap<String, String> responseSet = new HashMap<String, String>();
268 if (TextUtils.isEmpty(sParserFormat)) {
269 return responseSet;
270 }
271 UssdParser parserResult = new UssdParser(sParserFormat);
272 parserResult.newFromResponseString(inputResponse);
273 if (parserResult == null) {
274 return responseSet;
275 }
276
277 Vector<String> result = parserResult.getResult();
278
279 if (result == null) {
280 return responseSet;
281 }
282 for (int i = 0; i < result.size(); i++) {
283 if (responseFormat.containsKey(i)) {
284 String defineString = "";
285 if (responseDefine.containsKey(responseFormat.get(i))) {
286 for (int x = 0; x < responseDefine.get(responseFormat.get(i)).size(); x++) {
287 defineString = ((SsResultEntry) responseDefine.get(
288 responseFormat.get(i)).get(x)).getDefinitionByCompareValue(
289 result.get(i));
290 if (!TextUtils.isEmpty(defineString)) {
291 break;
292 }
293 }
294 // if status_code do not match definition value, we will set command error.
295 if (TAG_RESPONSE_STATUS.equals(responseFormat.get(i))) {
296 if (TextUtils.isEmpty(defineString)) {
297 responseSet.put(TAG_RESPONSE_STATUS_ERROR,
298 TAG_RESPONSE_STATUS_ERROR);
299 }
300 }
301 }
302 if (TextUtils.isEmpty(defineString)) {
303 responseSet.put(responseFormat.get(i), result.get(i));
304 } else {
305 responseSet.put(responseFormat.get(i), defineString);
306 }
307 }
308 }
309 return responseSet;
310 }
311 }
312
313 /**
314 * CarrierXmlParser parses command_result from xml and saves in SsResultEntry class.
315 */
316 public static class SsResultEntry {
317 String mDefinition;
318 String mCompareValue;
319
320 public SsResultEntry() {
321 }
322
323 @Override
324 public String toString() {
325 return "SsResultEntry mDefinition:" + mDefinition
326 + ", mCompareValue:" + mCompareValue;
327 }
328
329 /**
330 * If mCompareValue item is the same as compare value,it will return the mDefinition.
331 *
332 * @param inputValue This is the entry of response command's value.
333 * @return mDefinition or null.
334 */
335 public String getDefinitionByCompareValue(String inputValue) {
336 if (mCompareValue.equals(inputValue)) {
337 return mDefinition;
338 }
339 return null;
340 }
341 }
342
343 /**
344 * CarrierXmlParser parses feature from xml and saves in SsFeature class.
345 */
346 public class SsFeature {
347 public HashMap<SsEntry.SSAction, SsEntry> ssEntryHashMap =
348 new HashMap<SsEntry.SSAction, SsEntry>();
349 public HashMap<String, ArrayList<SsResultEntry>> responseCode =
350 new HashMap<String, ArrayList<SsResultEntry>>();
351
352 public SsFeature() {
353 }
354
355 private String getResponseCodeString() {
356 String result = "";
357 for (Map.Entry<String, ArrayList<SsResultEntry>> entry : responseCode.entrySet()) {
358 ArrayList<SsResultEntry> values = entry.getValue();
359 for (int i = 0; i < values.size(); i++) {
360 result += "value of i is " + ((SsResultEntry) values.get(i)).toString();
361 }
362 }
363 return result;
364 }
365
366 @Override
367 public String toString() {
368 return getResponseCodeString();
369 }
370
371 /**
372 * To get the caller id command by xml's structure.
373 *
374 * @param inputAction This is action_code of command item from xml.
375 */
376 public String getCommandStructure(SsEntry.SSAction inputAction) {
377 SsEntry entry = ssEntryHashMap.get(inputAction);
378 return entry.getCommandStructure();
379 }
380
381 /**
382 * To make the ussd command by xml structure
383 *
384 * @param inputAction This is action_code of command item from xml.
385 * @param inputInformationSet This is for parameter of command.
386 * @return The ussd command string.
387 */
388 public String makeCommand(SsEntry.SSAction inputAction,
389 Map<String, String> inputInformationSet) {
390 SsEntry entry = ssEntryHashMap.get(inputAction);
391 return entry.makeCommand(inputInformationSet);
392 }
393
394 /**
395 * To parse the special key and value from response message.
396 *
397 * @param inputAction This is action_code of command item from xml.
398 * @param inputResponse This is response message from network.
399 * @return The set includes specific key and value.
400 */
401 public HashMap<String, String> getResponseSet(SsEntry.SSAction inputAction,
402 String inputResponse) {
403 SsEntry entry = ssEntryHashMap.get(inputAction);
404 return entry.getResponseSet(inputResponse, responseCode);
405 }
406 }
407
408 /**
409 * @param context context to get res's xml
410 * @param carrierId carrier id of the current subscription. The carrier ID is an Android
411 * platform-wide identifier for a carrier. AOSP maintains carrier ID assignments in
412 * <a href="https://android.googlesource.com/platform/packages/providers/TelephonyProvider/+/master/assets/carrier_list.textpb">here</a>
413 */
414 public CarrierXmlParser(Context context, int carrierId) {
415 try {
416 int xmlResId = 0;
417 if (carrierId != TelephonyManager.UNKNOWN_CARRIER_ID) {
418 String xmlResIdName = "carrier_ss_string" + "_" + carrierId;
419 xmlResId = context.getResources().getIdentifier(xmlResIdName, "xml",
420 context.getPackageName());
421 }
422 if (xmlResId == 0) {
423 xmlResId = R.xml.carrier_ss_string;
424 }
425 Log.d(LOG_TAG, "carrierId: " + carrierId);
426
427 XmlResourceParser parser = context.getResources().getXml(xmlResId);
428 mFeatureMaps = parseXml(parser);
429 } catch (Exception e) {
430 Log.d(LOG_TAG, "Error parsing XML " + e.toString());
431 }
432 }
433
434 private HashMap<String, SsFeature> parseXml(XmlResourceParser parser) throws IOException {
435 HashMap<String, SsFeature> features = new HashMap<String, SsFeature>();
436 try {
437 int eventType = parser.getEventType();
438 while (eventType != XmlPullParser.END_DOCUMENT) {
439 if (eventType == XmlPullParser.START_TAG) {
440 if (TAG_REGULAR_PARSER.equals(parser.getName())) {
441 sParserFormat = readText(parser);
442 Log.d(LOG_TAG, "sParserFormat " + sParserFormat);
443 } else if (TAG_FEATURE.equals(parser.getName())) {
444 String featureName = getSpecificAttributeValue(parser, ATTR_NAME);
445 if (!TextUtils.isEmpty(featureName)) {
446 SsFeature feature = generateFeatureList(parser);
447 features.put(featureName, feature);
448 Log.d(LOG_TAG, "add " + featureName + " to map:" + feature.toString());
449 }
450 }
451 }
452 parser.next();
453 eventType = parser.getEventType();
454 }
455 } catch (XmlPullParserException e) {
456 e.printStackTrace();
457 }
458 return features;
459 }
460
461 private SsFeature generateFeatureList(XmlResourceParser parser)
462 throws XmlPullParserException, IOException {
463 SsFeature ssfeature = new SsFeature();
464 int outerDepth = parser.getDepth();
465
466 Log.d(LOG_TAG, "generateFeatureList outerDepth" + outerDepth);
467
468 while (parser.next() != XmlPullParser.END_DOCUMENT) {
469 Log.d(LOG_TAG, "generateFeatureList parser.getDepth()" + parser.getDepth());
470
471 int eventType = parser.getEventType();
472 if (eventType == XmlPullParser.END_TAG
473 && outerDepth == parser.getDepth()) {
474 break;
475 }
476
477 if (eventType != XmlPullParser.START_TAG) {
478 continue;
479 }
480 String name = parser.getName();
481 // Starts by looking for the command tag.
482 if (TAG_COMMAND.equals(name)) {
483 SsEntry entry = readCommandEntry(parser);
484 ssfeature.ssEntryHashMap.put(entry.ssAction, entry);
485 } else if (TAG_COMMAND_RESULT.equals(name)) {
486 readCommandResultEntry(parser, ssfeature);
487 }
488 }
489 return ssfeature;
490 }
491
492 private void readCommandResultEntry(XmlResourceParser parser, SsFeature ssFeature)
493 throws XmlPullParserException, IOException {
494 while (parser.next() != XmlPullParser.END_DOCUMENT) {
495 int eventType = parser.getEventType();
496 if (eventType == XmlPullParser.END_TAG
497 && TAG_COMMAND_RESULT.equals(parser.getName())) {
498 break;
499 }
500 if (eventType == XmlPullParser.START_TAG
501 && TAG_ENTRY.equals(parser.getName())) {
502 String key = getSpecificAttributeValue(parser, ATTR_RESULT_KEY);
503 if (!TextUtils.isEmpty(key)) {
504 SsResultEntry entry = new SsResultEntry();
505 entry.mDefinition = getSpecificAttributeValue(parser, ATTR_DEFINITION_KEY);
506 entry.mCompareValue = readText(parser);
507 if (ssFeature.responseCode.containsKey(key)) {
508 ssFeature.responseCode.get(key).add(entry);
509 } else {
510 ArrayList<SsResultEntry> arrayList = new ArrayList<>();
511 arrayList.add(entry);
512 ssFeature.responseCode.put(key, arrayList);
513 }
514 }
515 }
516 }
517 }
518
519 private SsEntry readCommandEntry(XmlResourceParser parser)
520 throws XmlPullParserException, IOException {
521 int outerDepth = parser.getDepth();
522 String command_action = getSpecificAttributeValue(parser, ATTR_NAME);
523 SsEntry entry = new SsEntry(command_action);
524
525 while (parser.next() != XmlPullParser.END_DOCUMENT) {
526 int eventType = parser.getEventType();
527 if (eventType == XmlPullParser.END_TAG
528 && outerDepth == parser.getDepth()) {
529 break;
530 }
531
532 if (eventType != XmlPullParser.START_TAG) {
533 continue;
534 }
535
536 String name = parser.getName();
537 if (TAG_SERVICE_CODE.equals(name)) {
538 entry.serviceCode = readText(parser);
539 } else if (TAG_ACTION_CODE.equals(name)) {
540 entry.actionCode = readText(parser);
541 } else if (TAG_PARAMETER.equals(name)) {
542 String number = getSpecificAttributeValue(parser, ATTR_PARAMETER_NUM);
543 if (!TextUtils.isEmpty(number)) {
544 readParameters(parser, entry, Integer.valueOf(number), TAG_PARAMETER);
545 }
546 } else if (TAG_RESPONSE_FORMAT.equals(name)) {
547 String number = getSpecificAttributeValue(parser, ATTR_PARAMETER_NUM);
548 if (!TextUtils.isEmpty(number)) {
549 readParameters(parser, entry, Integer.valueOf(number), TAG_RESPONSE_FORMAT);
550 }
551 }
552 }
553 Log.d(LOG_TAG, "ssEntry:" + entry.toString());
554 return entry;
555 }
556
557 private void readParameters(XmlResourceParser parser, SsEntry entry, int num, String parentTag)
558 throws IOException, XmlPullParserException {
559 Log.d(LOG_TAG, "readParameters() nume:" + num);
560 int i = 0;
561 while (i < num) {
562 if (parser.next() == XmlPullParser.START_TAG) {
563 String name = parser.getName();
564 if (TAG_ENTRY.equals(name)) {
565 String position = getSpecificAttributeValue(parser, ATTR_POSITION);
566 if (!TextUtils.isEmpty(position)) {
567 if (TAG_PARAMETER.equals(parentTag)) {
568 String value = readText(parser);
569 if (!TextUtils.isEmpty(value)) {
570 entry.commandParameter.put(Integer.valueOf(position), value);
571 }
572 } else if (TAG_RESPONSE_FORMAT.equals(parentTag)) {
573 String key = getSpecificAttributeValue(parser, ATTR_RESULT_KEY);
574 if (!TextUtils.isEmpty(key)) {
575 entry.responseFormat.put(Integer.valueOf(position), key);
576 }
577 }
578 i++;
579 }
580 }
581 }
582 }
583 }
584
585 private String getSpecificAttributeValue(XmlResourceParser parser, String attrTag) {
586 String value = "";
587 for (int i = 0; i < parser.getAttributeCount(); i++) {
588 if (attrTag.equals(parser.getAttributeName(i))) {
589 value = parser.getAttributeValue(i);
590 }
591 }
592 return value;
593 }
594
595 private String readText(XmlResourceParser parser) throws IOException, XmlPullParserException {
596 String result = "";
597 if (parser.next() == XmlPullParser.TEXT) {
598 result = parser.getText();
599 parser.nextTag();
600 }
601 return result;
602 }
603
604 /**
605 * CarrierXmlParser parses the xml and saves in mFeatureMap.
606 * To use this function get feature from the mFeatureMaps.
607 *
608 * @param inputFeatureName This is feature's name from xml.
609 */
610 public SsFeature getFeature(String inputFeatureName) {
611 return mFeatureMaps.get(inputFeatureName);
612 }
613
614 /**
615 * To check the command which is dialed by user is caller id command.
616 * <p>
617 * If it is a caller id command which sets to activate, return the {@code
618 * SsEntry.SSAction.UPDATE_ACTIVATE}.
619 * If it is a caller id command which sets to deactivate, return the {@code
620 * SsEntry.SSAction.UPDATE_DEACTIVATE}.
621 * If it is not a caller id command, return the {@code SsEntry.SSAction.UNKNOWN}.
622 *
623 * @param inputCommand This is caller id's ussd command which is dialed by user.
624 * @return {@link SsEntry.SSAction}
625 */
626 public SsEntry.SSAction getCallerIdUssdCommandAction(String inputCommand) {
627 if (isCallerIdActivate(inputCommand)) {
628 return SsEntry.SSAction.UPDATE_ACTIVATE;
629 }
630 if (isCallerIdDeactivate(inputCommand)) {
631 return SsEntry.SSAction.UPDATE_DEACTIVATE;
632 }
633 return SsEntry.SSAction.UNKNOWN;
634 }
635
636 private String getCallerIdActivateCommandFromXml() {
637 return getFeature(FEATURE_CALLER_ID).getCommandStructure(SsEntry.SSAction.UPDATE_ACTIVATE);
638 }
639
640 private String getCallerIdDeactivateCommandFromXml() {
641 return getFeature(FEATURE_CALLER_ID).getCommandStructure(
642 SsEntry.SSAction.UPDATE_DEACTIVATE);
643 }
644
645 private boolean isCallerIdActivate(String inputStr) {
646 String activateStr = getCallerIdActivateCommandFromXml();
647 return compareCommand(activateStr, inputStr);
648 }
649
650 private boolean isCallerIdDeactivate(String inputStr) {
651 String activateStr = getCallerIdDeactivateCommandFromXml();
652 return compareCommand(activateStr, inputStr);
653 }
654
655 private boolean compareCommand(String activateStr, String inputStr) {
656 String[] activateArray = activateStr.split("\\" + STAR_SIGN);
657 String[] inputArray = inputStr.split("\\" + STAR_SIGN);
658
659 if (activateArray.length == 0 || inputArray.length == 0) {
660 return false;
661 }
662 for (int i = 0; i < activateArray.length; i++) {
663 if (activateArray[i].startsWith(TAG_SIGN)) {
664 continue;
665 }
666 if (!activateArray[i].equals(inputArray[i])) {
667 Log.d(LOG_TAG, "compare fails:" + activateStr + "," + inputStr);
668 return false;
669 }
670 }
671 Log.d(LOG_TAG, "compare success");
672 return true;
673 }
674}