1/*
2 * Copyright (C) 2008 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.voicedialer;
18
19
20import android.content.Context;
21import android.content.Intent;
22import android.content.BroadcastReceiver;
23import com.android.internal.telephony.TelephonyIntents;
24import android.util.Log;
25import android.widget.Toast;
26
27public class VoiceDialerReceiver extends BroadcastReceiver {
28    private static final String TAG = "VoiceDialerReceiver";
29
30    @Override
31    public void onReceive(Context context, Intent intent) {
32        if (false) Log.d(TAG, "onReceive " + intent);
33
34        // fetch up useful stuff
35        String action = intent.getAction();
36        String host = intent.getData() != null ? intent.getData().getHost() : null;
37
38        // force recompilation of g2g on boot
39        if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
40            CommandRecognizerEngine.deleteCachedGrammarFiles(context);
41        }
42
43        // force recompilation if apps change, for 'OPEN' command
44        else if (Intent.ACTION_PACKAGE_ADDED.equals(action) ||
45                Intent.ACTION_PACKAGE_CHANGED.equals(action) ||
46                Intent.ACTION_PACKAGE_REMOVED.equals(action) ||
47                Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action) ||
48                Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action)) {
49            CommandRecognizerEngine.deleteCachedGrammarFiles(context);
50        }
51
52        // Voice Dialer Logging Enabled, *#*#8351#*#*
53        else if (TelephonyIntents.SECRET_CODE_ACTION.equals(action) && "8351".equals(host)) {
54            RecognizerLogger.enable(context);
55            Toast.makeText(context, R.string.logging_enabled, Toast.LENGTH_LONG).show();
56        }
57
58        // Voice Dialer Logging Disabled, *#*#8350#*#*
59        else if (TelephonyIntents.SECRET_CODE_ACTION.equals(action) && "8350".equals(host)) {
60            RecognizerLogger.disable(context);
61            Toast.makeText(context, R.string.logging_disabled, Toast.LENGTH_LONG).show();
62        }
63    }
64}
65