Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 856df43c authored by Zhihai Xu's avatar Zhihai Xu Committed by Android (Google) Code Review
Browse files

Merge "MAP 1.1 Review fixes" into klp-dev

parents e238a47f 5d2595f0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -40,7 +40,8 @@
            style="?android:attr/textAppearanceMedium"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dip"
            android:layout_marginTop="20dip"
            android:layout_marginBottom="20dip"
            android:text="@string/bluetooth_remember_choice" />

    </LinearLayout>
+10 −2
Original line number Diff line number Diff line
@@ -276,6 +276,8 @@
    <string name="bluetooth_connected_no_headset">Connected (no phone)</string>
    <!-- Bluetooth settings.  Message when connected to a device, except for media audio. [CHAR LIMIT=40] -->
    <string name="bluetooth_connected_no_a2dp">Connected (no media)</string>
    <!-- Bluetooth settings.  Message when connected to a device, except for map. [CHAR LIMIT=40] -->
    <string name="bluetooth_connected_no_map">Connected (no message access)</string>
    <!-- Bluetooth settings.  Message when connected to a device, except for phone/media audio. [CHAR LIMIT=40] -->
    <string name="bluetooth_connected_no_headset_no_a2dp">Connected (no phone or media)</string>
    <!-- Bluetooth settings.  Message when a device is disconnected -->
@@ -349,7 +351,7 @@
    <string name="bluetooth_connection_dialog_text">"Do you want to connect to \u0022<xliff:g id="device_name">%1$s</xliff:g>\u0022?"</string>

    <!-- Activity label of BluetoothPbPermissionActivity, also used as Strings in the permission dialog [CHAR LIMIT=none] -->
    <string name="bluetooth_phonebook_request">"Phone book request"</string>
    <string name="bluetooth_phonebook_request">"Phone book access request"</string>

    <!-- Bluetooth phone book permission Alert Activity text [CHAR LIMIT=none] -->
    <string name="bluetooth_pb_acceptance_dialog_text">%1$s wants to access your contacts and call history. Give access to %2$s?</string>
@@ -360,7 +362,7 @@
    <string name="bluetooth_pb_remember_choice">Don\'t ask again</string>

    <!-- Activity label of BluetoothMessagePermissionActivity, also used as Strings in the permission dialog [CHAR LIMIT=none] -->
    <string name="bluetooth_map_request">"Message request"</string>
    <string name="bluetooth_map_request">"Message access request"</string>

    <!-- Bluetooth message permission Alert Activity text [CHAR LIMIT=none] -->
    <string name="bluetooth_map_acceptance_dialog_text">%1$s wants to access your messages. Give access to %2$s?</string>
@@ -1147,6 +1149,8 @@
    <string name="bluetooth_profile_pan">Internet access</string>
    <!-- Bluetooth settings. The user-visible string that is used whenever referring to the PAN profile (sharing this device's Internet connection). [CHAR LIMIT=40]-->
    <string name="bluetooth_profile_pan_nap">Internet connection sharing</string>
    <!-- Bluetooth settings.  The user-visible string that is used whenever referring to the map profile. -->
    <string name="bluetooth_profile_map">Message Access</string>

    <!-- Bluetooth settings.  Message for disconnecting from the A2DP profile. [CHAR LIMIT=80] -->
    <string name="bluetooth_disconnect_a2dp_profile"><xliff:g id="device_name">%1$s</xliff:g> will be disconnected from media audio.</string>
@@ -1179,6 +1183,8 @@
    <string name="bluetooth_headset_profile_summary_connected">Connected to phone audio</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the OPP checkbox preference when OPP is connected. -->
    <string name="bluetooth_opp_profile_summary_connected">Connected to file transfer server</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the map checkbox preference when map is connected. -->
    <string name="bluetooth_map_profile_summary_connected">Connected to map</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the OPP checkbox preference when OPP is not connected. -->
    <string name="bluetooth_opp_profile_summary_not_connected">Not connected to file transfer server</string>
    <!-- Bluetooth settings. Connection options screen. The summary for the HID checkbox preference when HID is connected. -->
@@ -1202,6 +1208,8 @@
         for the PAN checkbox preference that describes how checking it
         will set the PAN profile as preferred. -->
    <string name="bluetooth_pan_profile_summary_use_for">Use for Internet access</string>
    <!-- Bluetooth settings.  Connection options screen.  The summary for the map checkbox preference that describes how checking it will set the map profile as preferred. -->
    <string name="bluetooth_map_profile_summary_use_for">Use for map</string>

    <!-- Bluetooth settings.  Dock Setting Title -->
    <string name="bluetooth_dock_settings">Dock Settings</string>
+22 −14
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Button;
import android.widget.CompoundButton.OnCheckedChangeListener;
@@ -64,6 +63,9 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL)) {
                int requestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                               BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
                if (requestType != mRequestType) return;
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                if (mDevice.equals(device)) dismissDialog();
            }
@@ -94,6 +96,8 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        mRequestType = i.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                     BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);

        if(DEBUG) Log.i(TAG, "onCreate() Request type: " + mRequestType);

        if (mRequestType == BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION) {
            showDialog(getString(R.string.bluetooth_connection_permission_request), mRequestType);
        } else if (mRequestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
@@ -117,6 +121,7 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        final AlertController.AlertParams p = mAlertParams;
        p.mIconId = android.R.drawable.ic_dialog_info;
        p.mTitle = title;
        if(DEBUG) Log.i(TAG, "showDialog() Request type: " + mRequestType + " this: " + this);
        switch(requestType)
        {
        case BluetoothDevice.REQUEST_TYPE_PROFILE_CONNECTION:
@@ -137,15 +142,16 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        setupAlert();

    }

    private String createDisplayText(String message) {
        String mMessage1 = message;
        return mMessage1;
    @Override
    public void onBackPressed() {
        /*we need an answer so ignore back button presses during auth */
        if(DEBUG) Log.i(TAG, "Back button pressed! ignoring");
        return;
    }

    private String createRemoteName()
    {
        String mRemoteName = mDevice != null ? mDevice.getAliasName() : null;

        if (mRemoteName == null) mRemoteName = getString(R.string.unknown);
        return mRemoteName;
    }
@@ -154,8 +160,8 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        String mRemoteName = createRemoteName();
        mView = getLayoutInflater().inflate(R.layout.bluetooth_connection_access, null);
        messageView = (TextView)mView.findViewById(R.id.message);
        messageView.setText(createDisplayText(getString(R.string.bluetooth_connection_dialog_text,
                mRemoteName)));
        messageView.setText(getString(R.string.bluetooth_connection_dialog_text,
                mRemoteName));
        return mView;
    }

@@ -177,8 +183,8 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        String mRemoteName = createRemoteName();
        mView = getLayoutInflater().inflate(R.layout.bluetooth_access, null);
        messageView = (TextView)mView.findViewById(R.id.message);
        messageView.setText(createDisplayText(getString(R.string.bluetooth_pb_acceptance_dialog_text,
                mRemoteName, mRemoteName)));
        messageView.setText(getString(R.string.bluetooth_pb_acceptance_dialog_text,
                mRemoteName, mRemoteName));
        createCheckbox(R.id.bluetooth_remember_choice);
        return mView;
    }
@@ -186,8 +192,8 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        String mRemoteName = createRemoteName();
        mView = getLayoutInflater().inflate(R.layout.bluetooth_access, null);
        messageView = (TextView)mView.findViewById(R.id.message);
        messageView.setText(createDisplayText(getString(R.string.bluetooth_map_acceptance_dialog_text,
                mRemoteName, mRemoteName)));
        messageView.setText(getString(R.string.bluetooth_map_acceptance_dialog_text,
                mRemoteName, mRemoteName));
        createCheckbox(R.id.bluetooth_remember_choice);
        return mView;
    }
@@ -221,6 +227,8 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        if (mReturnPackage != null && mReturnClass != null) {
            intent.setClassName(mReturnPackage, mReturnClass);
        }
        if(DEBUG) Log.i(TAG, "sendIntentToReceiver() Request type: " + mRequestType +
                " mReturnPackage" + mReturnPackage + " mReturnClass" + mReturnClass);

        intent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
                        allowed ? BluetoothDevice.CONNECTION_ACCESS_YES :
@@ -230,6 +238,7 @@ public class BluetoothPermissionActivity extends AlertActivity implements
            intent.putExtra(extraName, extraValue);
        }
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
        intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
        sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_ADMIN);
    }

@@ -276,7 +285,6 @@ public class BluetoothPermissionActivity extends AlertActivity implements
        }else if (permissionType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS){
            cachedDevice.setMessagePermissionChoice(permissionChoice);
        }

    }

}
+68 −26
Original line number Diff line number Diff line
@@ -36,7 +36,11 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {

    private static final String TAG = "BluetoothPermissionRequest";
    private static final boolean DEBUG = Utils.V;
    public static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth;
    private static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth;

    private static final String NOTIFICATION_TAG_PBAP = "Phonebook Access" ;
    private static final String NOTIFICATION_TAG_MAP = "Message Access";


    Context mContext;
    int mRequestType;
@@ -49,7 +53,7 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
        mContext = context;
        String action = intent.getAction();

        if (DEBUG) Log.d(TAG, "onReceive");
        if (DEBUG) Log.d(TAG, "onReceive" + action);

        if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_REQUEST)) {
            // convert broadcast intent into activity intent (same action string)
@@ -59,14 +63,8 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
            mReturnPackage = intent.getStringExtra(BluetoothDevice.EXTRA_PACKAGE_NAME);
            mReturnClass = intent.getStringExtra(BluetoothDevice.EXTRA_CLASS_NAME);

            Intent connectionAccessIntent = new Intent(action);
            connectionAccessIntent.setClass(context, BluetoothPermissionActivity.class);
            connectionAccessIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                            mRequestType);
            connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
            connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_PACKAGE_NAME, mReturnPackage);
            connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_CLASS_NAME, mReturnClass);
            if (DEBUG) Log.d(TAG, "onReceive request type: " + mRequestType + " return "
                    + mReturnPackage + "," + mReturnClass);

            // Check if user had made decisions on accepting or rejecting the phonebook access
            // request. If there is, reply the request and return, no need to start permission
@@ -75,8 +73,22 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
                return;
            }

            String deviceAddress = mDevice != null ? mDevice.getAddress() : null;
            Intent connectionAccessIntent = new Intent(action);
            connectionAccessIntent.setClass(context, BluetoothPermissionActivity.class);
            // We use the FLAG_ACTIVITY_MULTIPLE_TASK since we can have multiple concurrent access requests
            connectionAccessIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            connectionAccessIntent.setType(Integer.toString(mRequestType)); /* This is needed to create two pending
                                                                               intents to the same activity.
                                                                               The value is not used in the activity. */
            connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                            mRequestType);
            connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
            connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_PACKAGE_NAME, mReturnPackage);
            connectionAccessIntent.putExtra(BluetoothDevice.EXTRA_CLASS_NAME, mReturnClass);

            String deviceAddress = mDevice != null ? mDevice.getAddress() : null;
            String title = null;
            String message = null;
            PowerManager powerManager =
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);

@@ -93,31 +105,59 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
                deleteIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
                deleteIntent.putExtra(BluetoothDevice.EXTRA_CONNECTION_ACCESS_RESULT,
                        BluetoothDevice.CONNECTION_ACCESS_NO);

                Notification notification = new Notification(
                    android.R.drawable.stat_sys_data_bluetooth,
                    context.getString(R.string.bluetooth_connection_permission_request),
                    System.currentTimeMillis());
                deleteIntent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
                String deviceName = mDevice != null ? mDevice.getAliasName() : null;
                notification.setLatestEventInfo(context,
                    context.getString(R.string.bluetooth_connection_permission_request),
                    context.getString(R.string.bluetooth_connection_notif_message, deviceName),
                    PendingIntent.getActivity(context, 0, connectionAccessIntent, 0));
                notification.flags = Notification.FLAG_AUTO_CANCEL |
                                     Notification.FLAG_ONLY_ALERT_ONCE;
                notification.defaults = Notification.DEFAULT_SOUND;
                notification.deleteIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, 0);
                switch (mRequestType) {
                    case BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS:
                        title = context.getString(R.string.bluetooth_phonebook_request);
                        message = context.getString(R.string.bluetooth_pb_acceptance_dialog_text, deviceName, deviceName);
                        break;
                    case BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS:
                        title = context.getString(R.string.bluetooth_map_request);
                        message = context.getString(R.string.bluetooth_map_acceptance_dialog_text, deviceName, deviceName);
                        break;
                    default:
                        title = context.getString(R.string.bluetooth_connection_permission_request);
                        message = context.getString(R.string.bluetooth_connection_dialog_text, deviceName, deviceName);
                        break;
                }
                Notification notification = new Notification.Builder(context)
                                        .setContentTitle(title)
                                        .setTicker(message)
                                        .setContentText(message)
                                        .setSmallIcon(android.R.drawable.stat_sys_data_bluetooth)
                                        .setAutoCancel(true)
                                        .setPriority(Notification.PRIORITY_MAX)
                                        .setOnlyAlertOnce(false)
                                        .setDefaults(Notification.DEFAULT_ALL)
                                        .setContentIntent(PendingIntent.getActivity(context, 0, connectionAccessIntent, 0))
                                        .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
                                        .build();

                notification.flags |= Notification.FLAG_NO_CLEAR; /* cannot be set with the builder */

                NotificationManager notificationManager =
                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(NOTIFICATION_ID, notification);

                notificationManager.notify(getNotificationTag(mRequestType),NOTIFICATION_ID, notification);
            }
        } else if (action.equals(BluetoothDevice.ACTION_CONNECTION_ACCESS_CANCEL)) {
            // Remove the notification
            NotificationManager manager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
            manager.cancel(NOTIFICATION_ID);
            mRequestType = intent.getIntExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE,
                                        BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS);
            manager.cancel(getNotificationTag(mRequestType), NOTIFICATION_ID);
        }
    }

    private String getNotificationTag(int requestType) {
        if(requestType == BluetoothDevice.REQUEST_TYPE_PHONEBOOK_ACCESS) {
            return NOTIFICATION_TAG_PBAP;
        } else if(mRequestType == BluetoothDevice.REQUEST_TYPE_MESSAGE_ACCESS) {
            return NOTIFICATION_TAG_MAP;
        }
        return null;
    }

    /**
@@ -185,6 +225,7 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
                Log.e(TAG, "Bad messagePermission: " + messagePermission);
            }
        }
        if(DEBUG) Log.d(TAG,"checkUserChoice(): returning " + processed);
        return processed;
    }

@@ -204,6 +245,7 @@ public final class BluetoothPermissionRequest extends BroadcastReceiver {
            intent.putExtra(extraName, extraValue);
        }
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
        intent.putExtra(BluetoothDevice.EXTRA_ACCESS_REQUEST_TYPE, mRequestType);
        mContext.sendBroadcast(intent, android.Manifest.permission.BLUETOOTH_ADMIN);
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -140,6 +140,18 @@ final class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> {
                    mLocalNapRoleConnected = true;
                }
            }
            if (profile instanceof MapProfile) {
                profile.setPreferred(mDevice, true);
                refresh();
            }
        } else if (profile instanceof MapProfile &&
                newProfileState == BluetoothProfile.STATE_DISCONNECTED) {
            if (mProfiles.contains(profile)) {
                mRemovedProfiles.add(profile);
                mProfiles.remove(profile);
            }
            profile.setPreferred(mDevice, false);
            refresh();
        } else if (mLocalNapRoleConnected && profile instanceof PanProfile &&
                ((PanProfile) profile).isLocalRoleNap(mDevice) &&
                newProfileState == BluetoothProfile.STATE_DISCONNECTED) {
Loading