Created new UI library for device-policy related widgets
Test: manual verification
Bug: 175214581
Change-Id: I11300e61072d1858b955213304db3138129fc2ec
diff --git a/car-admin-ui-lib/Android.bp b/car-admin-ui-lib/Android.bp
new file mode 100644
index 0000000..853fe01
--- /dev/null
+++ b/car-admin-ui-lib/Android.bp
@@ -0,0 +1,27 @@
+// Copyright (C) 2020 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.
+
+// This project contains libraries that are used internally, mostly by
+// CarService and CarServiceHelperService.
+//
+// They're not meant to be used by other system apps and hence are not
+// supported.
+
+android_library {
+ name: "com.android.car.admin.ui",
+ srcs: [
+ "src/**/*.java",
+ ],
+ resource_dirs: ["src/main/res"],
+}
diff --git a/car-admin-ui-lib/AndroidManifest.xml b/car-admin-ui-lib/AndroidManifest.xml
new file mode 100644
index 0000000..51c8fa3
--- /dev/null
+++ b/car-admin-ui-lib/AndroidManifest.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2020 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.
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.car.admin.ui">
+</manifest>
diff --git a/car-admin-ui-lib/src/main/java/com/android/car/admin/ui/ManagedDeviceTextView.java b/car-admin-ui-lib/src/main/java/com/android/car/admin/ui/ManagedDeviceTextView.java
new file mode 100644
index 0000000..3fd5eee
--- /dev/null
+++ b/car-admin-ui-lib/src/main/java/com/android/car/admin/ui/ManagedDeviceTextView.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2020 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.car.admin.ui;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.TextView;
+
+/**
+ * Custom view used to display a disclaimer when a device is managed by a device owner.
+ */
+public final class ManagedDeviceTextView extends TextView {
+
+ public ManagedDeviceTextView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public ManagedDeviceTextView(Context context, AttributeSet attrs, int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public ManagedDeviceTextView(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+
+ if (isManagedDevice(context)) {
+ setText(R.string.car_admin_ui_managed_device_message);
+ } else {
+ setVisibility(View.GONE);
+ }
+ }
+
+ private static boolean isManagedDevice(Context context) {
+ PackageManager pm = context.getPackageManager();
+ if (!pm.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN)) return false;
+
+ DevicePolicyManager dpm = context.getSystemService(DevicePolicyManager.class);
+ return dpm != null && dpm.isDeviceManaged();
+ }
+}
diff --git a/car-admin-ui-lib/src/main/res/values/strings.xml b/car-admin-ui-lib/src/main/res/values/strings.xml
new file mode 100644
index 0000000..93dd615
--- /dev/null
+++ b/car-admin-ui-lib/src/main/res/values/strings.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2020 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.
+-->
+<resources>
+
+ <!-- TODO(b/175214581): STOPSHIP use proper sentence and remove translatable=false -->
+ <!-- Warn user that device is owned and managed by an enterprise (like a car rental company) [CHAR_LIMIT=50] -->
+ <string name="car_admin_ui_managed_device_message" translatable="false">This device is managed by an enterprise</string>
+
+</resources>