Merge "[CDM perm sync] Add user confirmation UI"
This commit is contained in:
committed by
Android (Google) Code Review
commit
07e69f96d8
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2022 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/activity_confirmation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/dialog_background"
|
||||
android:elevation="16dp"
|
||||
android:maxHeight="400dp"
|
||||
android:orientation="vertical"
|
||||
android:padding="18dp"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<!-- Do NOT change the ID of the root LinearLayout above: it's referenced in CTS tests. -->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="12dp"
|
||||
style="@*android:style/TextAppearance.Widget.Toolbar.Title"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/summary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:gravity="center"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="end">
|
||||
|
||||
<!-- Do NOT change the IDs of the buttons: they are referenced in CTS tests. -->
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_negative"
|
||||
style="@android:style/Widget.Material.Button.Borderless.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/consent_no"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_positive"
|
||||
style="@android:style/Widget.Material.Button.Borderless.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/consent_yes" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -73,4 +73,15 @@
|
||||
|
||||
<!-- Negative button for the device-app association consent dialog [CHAR LIMIT=30] -->
|
||||
<string name="consent_no">Don\u2019t allow</string>
|
||||
|
||||
<!-- ================== System data transfer ==================== -->
|
||||
<!-- Title of the permission sync confirmation dialog. [CHAR LIMIT=60] -->
|
||||
<string name="permission_sync_confirmation_title">Transfer app permissions to your
|
||||
watch</string>
|
||||
|
||||
<!-- Text of the permission sync explanation in the confirmation dialog. [CHAR LIMIT=400] -->
|
||||
<string name="permission_sync_summary">To make it easier to set up your watch,
|
||||
apps installed on your watch during setup will use the same permissions as your phone.\n\n
|
||||
These permissions may include access to your watch\u2019s microphone and location.</string>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.companiondevicemanager;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.companion.SystemDataTransferRequest;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.ResultReceiver;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* This activity manages the UI of companion device data transfer.
|
||||
*/
|
||||
public class CompanionDeviceDataTransferActivity extends Activity {
|
||||
|
||||
private static final String LOG_TAG = CompanionDeviceDataTransferActivity.class.getSimpleName();
|
||||
|
||||
// UI -> SystemDataTransferProcessor
|
||||
private static final int RESULT_CODE_SYSTEM_DATA_TRANSFER_ALLOWED = 0;
|
||||
private static final int RESULT_CODE_SYSTEM_DATA_TRANSFER_DISALLOWED = 1;
|
||||
private static final String EXTRA_SYSTEM_DATA_TRANSFER_REQUEST = "system_data_transfer_request";
|
||||
private static final String EXTRA_SYSTEM_DATA_TRANSFER_RESULT_RECEIVER =
|
||||
"system_data_transfer_result_receiver";
|
||||
|
||||
private SystemDataTransferRequest mRequest;
|
||||
private ResultReceiver mCdmServiceReceiver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Log.i(LOG_TAG, "Creating UI for data transfer confirmation.");
|
||||
|
||||
getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
|
||||
|
||||
setContentView(R.layout.data_transfer_confirmation);
|
||||
|
||||
TextView titleView = findViewById(R.id.title);
|
||||
TextView summaryView = findViewById(R.id.summary);
|
||||
ListView listView = findViewById(R.id.device_list);
|
||||
listView.setVisibility(View.GONE);
|
||||
Button allowButton = findViewById(R.id.btn_positive);
|
||||
Button disallowButton = findViewById(R.id.btn_negative);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
mRequest = intent.getParcelableExtra(EXTRA_SYSTEM_DATA_TRANSFER_REQUEST);
|
||||
mCdmServiceReceiver = intent.getParcelableExtra(EXTRA_SYSTEM_DATA_TRANSFER_RESULT_RECEIVER);
|
||||
|
||||
requireNonNull(mRequest);
|
||||
requireNonNull(mCdmServiceReceiver);
|
||||
|
||||
if (mRequest.isPermissionSyncAllPackages()
|
||||
|| !mRequest.getPermissionSyncPackages().isEmpty()) {
|
||||
titleView.setText(Html.fromHtml(getString(
|
||||
R.string.permission_sync_confirmation_title), 0));
|
||||
summaryView.setText(getString(R.string.permission_sync_summary));
|
||||
allowButton.setOnClickListener(v -> allow());
|
||||
disallowButton.setOnClickListener(v -> disallow());
|
||||
}
|
||||
}
|
||||
|
||||
private void allow() {
|
||||
Log.i(LOG_TAG, "allow()");
|
||||
|
||||
sendDataToReceiver(RESULT_CODE_SYSTEM_DATA_TRANSFER_ALLOWED);
|
||||
|
||||
setResultAndFinish(RESULT_CODE_SYSTEM_DATA_TRANSFER_ALLOWED);
|
||||
}
|
||||
|
||||
private void disallow() {
|
||||
Log.i(LOG_TAG, "disallow()");
|
||||
|
||||
sendDataToReceiver(RESULT_CODE_SYSTEM_DATA_TRANSFER_DISALLOWED);
|
||||
|
||||
setResultAndFinish(RESULT_CODE_SYSTEM_DATA_TRANSFER_DISALLOWED);
|
||||
}
|
||||
|
||||
private void sendDataToReceiver(int cdmResultCode) {
|
||||
Bundle data = new Bundle();
|
||||
data.putParcelable(EXTRA_SYSTEM_DATA_TRANSFER_REQUEST, mRequest);
|
||||
mCdmServiceReceiver.send(cdmResultCode, data);
|
||||
}
|
||||
|
||||
private void setResultAndFinish(int cdmResultCode) {
|
||||
setResult(cdmResultCode == RESULT_CODE_SYSTEM_DATA_TRANSFER_ALLOWED
|
||||
? RESULT_OK : RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user