| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.app; |
| 18 |
|
| 19 |
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; |
| 20 |
|
| 21 |
import android.app.AlertDialog; |
| 22 |
import android.content.Context; |
| 23 |
import android.content.DialogInterface; |
| 24 |
import android.content.Intent; |
| 25 |
import android.location.LocationManagerInternal; |
| 26 |
import android.os.Bundle; |
| 27 |
import android.os.Handler; |
| 28 |
import android.os.Message; |
| 29 |
import android.util.Log; |
| 30 |
|
| 31 |
import com.android.internal.R; |
| 32 |
import com.android.internal.location.GpsNetInitiatedHandler; |
| 33 |
import com.android.server.LocalServices; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class NetInitiatedActivity extends AlertActivity implements DialogInterface.OnClickListener { |
| 40 |
|
| 41 |
private static final String TAG = "NetInitiatedActivity"; |
| 42 |
|
| 43 |
private static final boolean DEBUG = true; |
| 44 |
|
| 45 |
private static final int POSITIVE_BUTTON = AlertDialog.BUTTON_POSITIVE; |
| 46 |
private static final int NEGATIVE_BUTTON = AlertDialog.BUTTON_NEGATIVE; |
| 47 |
|
| 48 |
private static final int GPS_NO_RESPONSE_TIME_OUT = 1; |
| 49 |
|
| 50 |
private int notificationId = -1; |
| 51 |
private int timeout = -1; |
| 52 |
private int default_response = -1; |
| 53 |
private int default_response_timeout = 6; |
| 54 |
|
| 55 |
private final Handler mHandler = new Handler() { |
| 56 |
public void handleMessage(Message msg) { |
| 57 |
switch (msg.what) { |
| 58 |
case GPS_NO_RESPONSE_TIME_OUT: { |
| 59 |
if (notificationId != -1) { |
| 60 |
sendUserResponse(default_response); |
| 61 |
} |
| 62 |
finish(); |
| 63 |
} |
| 64 |
break; |
| 65 |
default: |
| 66 |
} |
| 67 |
} |
| 68 |
}; |
| 69 |
|
| 70 |
@Override |
| 71 |
protected void onCreate(Bundle savedInstanceState) { |
| 72 |
super.onCreate(savedInstanceState); |
| 73 |
|
| 74 |
getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); |
| 75 |
|
| 76 |
|
| 77 |
final Intent intent = getIntent(); |
| 78 |
final AlertController.AlertParams p = mAlertParams; |
| 79 |
Context context = getApplicationContext(); |
| 80 |
p.mTitle = intent.getStringExtra(GpsNetInitiatedHandler.NI_INTENT_KEY_TITLE); |
| 81 |
p.mMessage = intent.getStringExtra(GpsNetInitiatedHandler.NI_INTENT_KEY_MESSAGE); |
| 82 |
p.mPositiveButtonText = String.format(context.getString(R.string.gpsVerifYes)); |
| 83 |
p.mPositiveButtonListener = this; |
| 84 |
p.mNegativeButtonText = String.format(context.getString(R.string.gpsVerifNo)); |
| 85 |
p.mNegativeButtonListener = this; |
| 86 |
|
| 87 |
notificationId = intent.getIntExtra(GpsNetInitiatedHandler.NI_INTENT_KEY_NOTIF_ID, -1); |
| 88 |
timeout = intent.getIntExtra(GpsNetInitiatedHandler.NI_INTENT_KEY_TIMEOUT, default_response_timeout); |
| 89 |
default_response = intent.getIntExtra(GpsNetInitiatedHandler.NI_INTENT_KEY_DEFAULT_RESPONSE, GpsNetInitiatedHandler.GPS_NI_RESPONSE_ACCEPT); |
| 90 |
if (DEBUG) Log.d(TAG, "onCreate() : notificationId: " + notificationId + " timeout: " + timeout + " default_response:" + default_response); |
| 91 |
|
| 92 |
mHandler.sendMessageDelayed(mHandler.obtainMessage(GPS_NO_RESPONSE_TIME_OUT), (timeout * 1000)); |
| 93 |
setupAlert(); |
| 94 |
} |
| 95 |
|
| 96 |
@Override |
| 97 |
protected void onResume() { |
| 98 |
super.onResume(); |
| 99 |
if (DEBUG) Log.d(TAG, "onResume"); |
| 100 |
} |
| 101 |
|
| 102 |
@Override |
| 103 |
protected void onPause() { |
| 104 |
super.onPause(); |
| 105 |
if (DEBUG) Log.d(TAG, "onPause"); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public void onClick(DialogInterface dialog, int which) { |
| 112 |
if (which == POSITIVE_BUTTON) { |
| 113 |
sendUserResponse(GpsNetInitiatedHandler.GPS_NI_RESPONSE_ACCEPT); |
| 114 |
} |
| 115 |
if (which == NEGATIVE_BUTTON) { |
| 116 |
sendUserResponse(GpsNetInitiatedHandler.GPS_NI_RESPONSE_DENY); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
finish(); |
| 121 |
notificationId = -1; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
private void sendUserResponse(int response) { |
| 126 |
if (DEBUG) Log.d(TAG, "sendUserResponse, response: " + response); |
| 127 |
LocationManagerInternal lm = LocalServices.getService(LocationManagerInternal.class); |
| 128 |
lm.sendNiResponse(notificationId, response); |
| 129 |
} |
| 130 |
} |