├── .github
├── scripts
│ └── gradlew_recursive.sh
└── workflows
│ ├── android.yml
│ └── copy-branch.yml
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── ManagedConfigurations
├── .google
│ └── packaging.yaml
├── README.md
├── app
│ ├── build.gradle.kts
│ └── src
│ │ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── android
│ │ │ ├── common
│ │ │ ├── activities
│ │ │ │ └── SampleActivityBase.kt
│ │ │ └── logger
│ │ │ │ ├── Log.java
│ │ │ │ ├── LogFragment.java
│ │ │ │ ├── LogNode.java
│ │ │ │ ├── LogView.java
│ │ │ │ ├── LogWrapper.java
│ │ │ │ └── MessageOnlyLogFilter.java
│ │ │ └── managedconfigurations
│ │ │ ├── EnterpriseReporter.kt
│ │ │ ├── MainActivity.kt
│ │ │ └── ManagedConfigurationsFragment.kt
│ │ └── res
│ │ ├── drawable-hdpi
│ │ └── tile.9.png
│ │ ├── layout-w720dp
│ │ └── activity_main.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── fragment_managed_configurations.xml
│ │ ├── menu
│ │ └── main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-sw600dp
│ │ ├── dimens.xml
│ │ └── styles.xml
│ │ ├── values
│ │ ├── dimens.xml
│ │ ├── restriction_values.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── app_restrictions.xml
├── build.gradle.kts
├── gradle.properties
├── gradle
│ ├── libs.versions.toml
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshots
│ ├── app_feedback.gif
│ ├── big_icon.png
│ ├── main.png
│ ├── setup_testdpc.gif
│ └── update_managed_configurations.gif
└── settings.gradle.kts
├── README.md
├── Work-profile-codelab
├── .gitignore
├── LICENSE
├── README.md
├── app-finished
│ ├── .gitignore
│ ├── build.gradle.kts
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── workprofile
│ │ │ └── ExampleInstrumentedTest.kt
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── workprofile
│ │ │ │ ├── ContactsAdapter.kt
│ │ │ │ └── MainActivity.kt
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ ├── ic_launcher_foreground.xml
│ │ │ └── ic_person_primary_40dp.xml
│ │ │ ├── drawable
│ │ │ ├── ic_launcher_background.xml
│ │ │ └── ic_person_green_40dp.xml
│ │ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ └── contact_item_layout.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── workprofile
│ │ └── ExampleUnitTest.kt
├── app-starter
│ ├── .gitignore
│ ├── build.gradle.kts
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── workprofile
│ │ │ └── ExampleInstrumentedTest.kt
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── workprofile
│ │ │ │ ├── ContactsAdapter.kt
│ │ │ │ └── MainActivity.kt
│ │ └── res
│ │ │ ├── drawable-v24
│ │ │ ├── ic_launcher_foreground.xml
│ │ │ └── ic_person_primary_40dp.xml
│ │ │ ├── drawable
│ │ │ ├── ic_launcher_background.xml
│ │ │ └── ic_person_green_40dp.xml
│ │ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ └── contact_item_layout.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── workprofile
│ │ └── ExampleUnitTest.kt
├── build.gradle.kts
├── gradle.properties
├── gradle
│ ├── libs.versions.toml
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle.kts
└── renovate.json
/.github/scripts/gradlew_recursive.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Copyright (C) 2020 The Android Open Source Project
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # https://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | set -xe
18 |
19 | # Default Gradle settings are not optimal for Android builds, override them
20 | # here to make the most out of the GitHub Actions build servers
21 | GRADLE_OPTS="$GRADLE_OPTS -Xms4g -Xmx4g"
22 | GRADLE_OPTS="$GRADLE_OPTS -XX:+HeapDumpOnOutOfMemoryError"
23 | GRADLE_OPTS="$GRADLE_OPTS -Dorg.gradle.daemon=false"
24 | GRADLE_OPTS="$GRADLE_OPTS -Dorg.gradle.workers.max=2"
25 | GRADLE_OPTS="$GRADLE_OPTS -Dkotlin.incremental=false"
26 | GRADLE_OPTS="$GRADLE_OPTS -Dkotlin.compiler.execution.strategy=in-process"
27 | GRADLE_OPTS="$GRADLE_OPTS -Dfile.encoding=UTF-8"
28 | export GRADLE_OPTS
29 |
30 | # Crawl all gradlew files which indicate an Android project
31 | # You may edit this if your repo has a different project structure
32 | for GRADLEW in `find . -name "gradlew"` ; do
33 | SAMPLE=$(dirname "${GRADLEW}")
34 | # Tell Gradle that this is a CI environment and disable parallel compilation
35 | bash "$GRADLEW" -p "$SAMPLE" -Pci --no-parallel --stacktrace $@
36 | done
37 |
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2020 The Android Open Source Project
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | name: Android CI
16 |
17 | on:
18 | workflow_dispatch:
19 | push:
20 | branches: [ main ]
21 | pull_request:
22 | branches: [ main ]
23 |
24 | jobs:
25 |
26 | build:
27 | name: Build
28 | runs-on: ubuntu-latest
29 |
30 | steps:
31 | - uses: actions/checkout@v2
32 | - name: set up JDK 21
33 | uses: actions/setup-java@v4
34 | with:
35 | distribution: 'jetbrains'
36 | java-version: '21'
37 | - name: Build project
38 | run: .github/scripts/gradlew_recursive.sh assembleDebug
39 | - name: Zip artifacts
40 | run: zip -r assemble.zip . -i '**/build/*.apk' '**/build/*.aab' '**/build/*.aar' '**/build/*.so'
41 | - name: Upload artifacts
42 | uses: actions/upload-artifact@v4
43 | with:
44 | name: assemble
45 | path: assemble.zip
46 |
--------------------------------------------------------------------------------
/.github/workflows/copy-branch.yml:
--------------------------------------------------------------------------------
1 | # Duplicates default main branch to the old master branch
2 |
3 | name: Duplicates main to old master branch
4 |
5 | # Controls when the action will run. Triggers the workflow on push or pull request
6 | # events but only for the main branch
7 | on:
8 | workflow_dispatch:
9 | push:
10 | branches: [ main ]
11 |
12 | # Add this permissions block at the workflow level
13 | permissions:
14 | contents: write # Allows the GITHUB_TOKEN to write to the repository contents
15 |
16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel
17 | jobs:
18 | # This workflow contains a single job called "copy-branch"
19 | copy-branch:
20 | # The type of runner that the job will run on
21 | runs-on: ubuntu-latest
22 |
23 | # Steps represent a sequence of tasks that will be executed as part of the job
24 | steps:
25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it,
26 | # but specifies master branch (old default).
27 | - uses: actions/checkout@v2
28 | with:
29 | fetch-depth: 0
30 | ref: master
31 |
32 | - run: |
33 | git config user.name github-actions
34 | git config user.email github-actions@github.com
35 | git merge origin/main
36 | git push
37 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Mac files
6 | .DS_Store
7 |
8 | # files for the dex VM
9 | *.dex
10 |
11 | # Java class files
12 | *.class
13 |
14 | # generated files
15 | bin/
16 | gen/
17 |
18 | # Ignore gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 | proguard-project.txt
28 |
29 | # Eclipse files
30 | .project
31 | .classpath
32 | .settings/
33 |
34 | # Android Studio/IDEA
35 | *.iml
36 | .idea
37 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows
28 | [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/).
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | Copyright [yyyy] [name of copyright owner]
179 |
180 | Licensed under the Apache License, Version 2.0 (the "License");
181 | you may not use this file except in compliance with the License.
182 | You may obtain a copy of the License at
183 |
184 | http://www.apache.org/licenses/LICENSE-2.0
185 |
186 | Unless required by applicable law or agreed to in writing, software
187 | distributed under the License is distributed on an "AS IS" BASIS,
188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189 | See the License for the specific language governing permissions and
190 | limitations under the License.
191 |
192 |
--------------------------------------------------------------------------------
/ManagedConfigurations/.google/packaging.yaml:
--------------------------------------------------------------------------------
1 |
2 | # GOOGLE SAMPLE PACKAGING DATA
3 | #
4 | # This file is used by Google as part of our samples packaging process.
5 | # End users may safely ignore this file. It has no relevance to other systems.
6 | ---
7 | status: PUBLISHED
8 | technologies: [Android]
9 | categories: [Enterprise]
10 | languages: [Java]
11 | solutions: [Mobile]
12 | github: android/enterprise
13 | level: ADVANCED
14 | icon: screenshots/big_icon.png
15 | apiRefs:
16 | - android:android.content.RestrictionsManager
17 | license: apache2
18 |
--------------------------------------------------------------------------------
/ManagedConfigurations/README.md:
--------------------------------------------------------------------------------
1 |
2 | Android Managed Configuration Sample
3 | ====================================
4 |
5 | A basic app showing how to allow a device administrator to configurate
6 | an application using the Android Device Administration API.
7 | The app exports a managed configuration that enables or disables a UI control. Device Administration applications are able to enforce a specific value for this policy, as directed by enterprise administrators.
8 |
9 | Introduction
10 | ------------
11 |
12 | Managed configurations, previously known as application restrictions, allow the organization's IT admin to remotely specify settings for apps. This capability is particularly useful for organization-approved apps deployed to a work profile.
13 |
14 | For example, an organization might require that approved apps allow the IT admin to:
15 |
16 | * Allow or block URLs for a web browser
17 | * Configure whether an app is allowed to sync content via cellular, or just by Wi-Fi
18 | * Configure the app's email settings
19 |
20 | You can find additional information about Managed configurations in the [Set up managed configurations][1] article.
21 |
22 | * Screenshots
23 |
24 |
25 |
26 |
27 | [1]: https://developer.android.com/work/managed-configurations
28 |
29 | Application Feedback
30 | --------------------
31 |
32 | The sample application uses the Jetpack Enterprise's app feedback API to send a messages back to the EMM when a new configuration is received for a couple of the available options.
33 |
34 | Testing
35 | -------
36 |
37 | The application can be tested locally using the TestDPC application available on the [Play Store][2] and on [github][3].
38 |
39 | You can follow he guide on github to understand how to setup TestDPC on a device and how to update the manage configuration of this demo application when installed in an a managed profile. We're providing here a couple of animations to show this process:
40 |
41 | * Setup TestDPC
42 |
43 |
44 |
45 | * Update Managed Configurations
46 |
47 |
48 |
49 | * Receive App Feedback
50 |
51 |
52 |
53 | [2]: https://play.google.com/store/apps/details?id=com.afwsamples.testdpc
54 | [3]: https://github.com/googlesamples/android-testdpc
55 |
56 | Pre-requisites
57 | --------------
58 |
59 | - Android Studio Dolphin | 2021.3.1
60 |
61 | Getting Started
62 | ---------------
63 |
64 | This sample uses the Gradle build system. To build this project, use the
65 | "gradlew build" command or use "Import Project" in Android Studio.
66 |
67 | Support
68 | -------
69 |
70 | - Stack Overflow: http://stackoverflow.com/questions/tagged/android
71 |
72 | If you've found an error in this sample, please file an issue:
73 | https://github.com/android/enterprise-samples/issues
74 |
75 | Patches are encouraged, and may be submitted by forking this project and
76 | submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
77 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
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 |
17 | plugins {
18 | alias(libs.plugins.android.application)
19 | alias(libs.plugins.kotlin.android)
20 | }
21 |
22 | android {
23 | namespace = "com.example.android.managedconfigurations"
24 | compileSdk = 35
25 |
26 | defaultConfig {
27 | applicationId = "com.example.android.managedconfigurations"
28 | minSdk = 21
29 | targetSdk = 35
30 | versionCode = 1
31 | versionName = "1.0"
32 |
33 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
34 | }
35 |
36 | buildTypes {
37 | release {
38 | isMinifyEnabled = false
39 | proguardFiles(
40 | getDefaultProguardFile("proguard-android-optimize.txt"),
41 | "proguard-rules.pro"
42 | )
43 | }
44 | }
45 | compileOptions {
46 | sourceCompatibility = JavaVersion.VERSION_11
47 | targetCompatibility = JavaVersion.VERSION_11
48 | }
49 | kotlinOptions {
50 | jvmTarget = "11"
51 | }
52 | buildFeatures {
53 | viewBinding = true
54 | }
55 | }
56 |
57 | dependencies {
58 | implementation(libs.androidx.core.ktx)
59 | implementation(libs.androidx.appcompat)
60 | implementation(libs.material)
61 | implementation(libs.androidx.activity)
62 | implementation(libs.androidx.constraintlayout)
63 | implementation(libs.jetbrains.kotlin.stdlib.jdk7)
64 | implementation(libs.androidx.enterprise.feedback)
65 | // For testing enterprise feedback in isolation
66 | testImplementation(libs.androidx.enterprise.feedback.testing)
67 | testImplementation(libs.junit)
68 | androidTestImplementation(libs.androidx.junit)
69 | androidTestImplementation(libs.androidx.espresso.core)
70 | }
71 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
21 |
22 |
28 |
29 |
32 |
33 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/common/activities/SampleActivityBase.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 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 | package com.example.android.common.activities
17 |
18 | import androidx.appcompat.app.AppCompatActivity
19 | import com.example.android.common.logger.Log
20 | import com.example.android.common.logger.LogWrapper
21 |
22 | /**
23 | * Base launcher activity, to handle most of the common plumbing for samples.
24 | */
25 | abstract class SampleActivityBase : AppCompatActivity() {
26 |
27 | override fun onStart() {
28 | super.onStart()
29 | initializeLogging()
30 | }
31 |
32 | /**
33 | * Set up targets to receive log data
34 | */
35 | open fun initializeLogging() {
36 | // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
37 | // Wraps Android's native log framework
38 | val logWrapper = LogWrapper()
39 | Log.setLogNode(logWrapper)
40 | Log.i(TAG, "Ready")
41 | }
42 |
43 | companion object {
44 | const val TAG = "SampleActivityBase"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/common/logger/Log.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 | package com.example.android.common.logger;
17 |
18 | /**
19 | * Helper class for a list (or tree) of LoggerNodes.
20 | *
21 | *
When this is set as the head of the list,
22 | * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
23 | * Most of the methods in this class server only to map a method call in Log to its equivalent
24 | * in LogNode.
25 | */
26 | public class Log {
27 | // Grabbing the native values from Android's native logging facilities,
28 | // to make for easy migration and interop.
29 | public static final int NONE = -1;
30 | public static final int VERBOSE = android.util.Log.VERBOSE;
31 | public static final int DEBUG = android.util.Log.DEBUG;
32 | public static final int INFO = android.util.Log.INFO;
33 | public static final int WARN = android.util.Log.WARN;
34 | public static final int ERROR = android.util.Log.ERROR;
35 | public static final int ASSERT = android.util.Log.ASSERT;
36 |
37 | // Stores the beginning of the LogNode topology.
38 | private static LogNode mLogNode;
39 |
40 | /**
41 | * Returns the next LogNode in the linked list.
42 | */
43 | public static LogNode getLogNode() {
44 | return mLogNode;
45 | }
46 |
47 | /**
48 | * Sets the LogNode data will be sent to.
49 | */
50 | public static void setLogNode(LogNode node) {
51 | mLogNode = node;
52 | }
53 |
54 | /**
55 | * Instructs the LogNode to print the log data provided. Other LogNodes can
56 | * be chained to the end of the LogNode as desired.
57 | *
58 | * @param priority Log level of the data being logged. Verbose, Error, etc.
59 | * @param tag Tag for for the log data. Can be used to organize log statements.
60 | * @param msg The actual message to be logged.
61 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
62 | * to extract and print useful information.
63 | */
64 | public static void println(int priority, String tag, String msg, Throwable tr) {
65 | if (mLogNode != null) {
66 | mLogNode.println(priority, tag, msg, tr);
67 | }
68 | }
69 |
70 | /**
71 | * Instructs the LogNode to print the log data provided. Other LogNodes can
72 | * be chained to the end of the LogNode as desired.
73 | *
74 | * @param priority Log level of the data being logged. Verbose, Error, etc.
75 | * @param tag Tag for for the log data. Can be used to organize log statements.
76 | * @param msg The actual message to be logged. The actual message to be logged.
77 | */
78 | public static void println(int priority, String tag, String msg) {
79 | println(priority, tag, msg, null);
80 | }
81 |
82 | /**
83 | * Prints a message at VERBOSE priority.
84 | *
85 | * @param tag Tag for for the log data. Can be used to organize log statements.
86 | * @param msg The actual message to be logged.
87 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
88 | * to extract and print useful information.
89 | */
90 | public static void v(String tag, String msg, Throwable tr) {
91 | println(VERBOSE, tag, msg, tr);
92 | }
93 |
94 | /**
95 | * Prints a message at VERBOSE priority.
96 | *
97 | * @param tag Tag for for the log data. Can be used to organize log statements.
98 | * @param msg The actual message to be logged.
99 | */
100 | public static void v(String tag, String msg) {
101 | v(tag, msg, null);
102 | }
103 |
104 |
105 | /**
106 | * Prints a message at DEBUG priority.
107 | *
108 | * @param tag Tag for for the log data. Can be used to organize log statements.
109 | * @param msg The actual message to be logged.
110 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
111 | * to extract and print useful information.
112 | */
113 | public static void d(String tag, String msg, Throwable tr) {
114 | println(DEBUG, tag, msg, tr);
115 | }
116 |
117 | /**
118 | * Prints a message at DEBUG priority.
119 | *
120 | * @param tag Tag for for the log data. Can be used to organize log statements.
121 | * @param msg The actual message to be logged.
122 | */
123 | public static void d(String tag, String msg) {
124 | d(tag, msg, null);
125 | }
126 |
127 | /**
128 | * Prints a message at INFO priority.
129 | *
130 | * @param tag Tag for for the log data. Can be used to organize log statements.
131 | * @param msg The actual message to be logged.
132 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
133 | * to extract and print useful information.
134 | */
135 | public static void i(String tag, String msg, Throwable tr) {
136 | println(INFO, tag, msg, tr);
137 | }
138 |
139 | /**
140 | * Prints a message at INFO priority.
141 | *
142 | * @param tag Tag for for the log data. Can be used to organize log statements.
143 | * @param msg The actual message to be logged.
144 | */
145 | public static void i(String tag, String msg) {
146 | i(tag, msg, null);
147 | }
148 |
149 | /**
150 | * Prints a message at WARN priority.
151 | *
152 | * @param tag Tag for for the log data. Can be used to organize log statements.
153 | * @param msg The actual message to be logged.
154 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
155 | * to extract and print useful information.
156 | */
157 | public static void w(String tag, String msg, Throwable tr) {
158 | println(WARN, tag, msg, tr);
159 | }
160 |
161 | /**
162 | * Prints a message at WARN priority.
163 | *
164 | * @param tag Tag for for the log data. Can be used to organize log statements.
165 | * @param msg The actual message to be logged.
166 | */
167 | public static void w(String tag, String msg) {
168 | w(tag, msg, null);
169 | }
170 |
171 | /**
172 | * Prints a message at WARN priority.
173 | *
174 | * @param tag Tag for for the log data. Can be used to organize log statements.
175 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
176 | * to extract and print useful information.
177 | */
178 | public static void w(String tag, Throwable tr) {
179 | w(tag, null, tr);
180 | }
181 |
182 | /**
183 | * Prints a message at ERROR priority.
184 | *
185 | * @param tag Tag for for the log data. Can be used to organize log statements.
186 | * @param msg The actual message to be logged.
187 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
188 | * to extract and print useful information.
189 | */
190 | public static void e(String tag, String msg, Throwable tr) {
191 | println(ERROR, tag, msg, tr);
192 | }
193 |
194 | /**
195 | * Prints a message at ERROR priority.
196 | *
197 | * @param tag Tag for for the log data. Can be used to organize log statements.
198 | * @param msg The actual message to be logged.
199 | */
200 | public static void e(String tag, String msg) {
201 | e(tag, msg, null);
202 | }
203 |
204 | /**
205 | * Prints a message at ASSERT priority.
206 | *
207 | * @param tag Tag for for the log data. Can be used to organize log statements.
208 | * @param msg The actual message to be logged.
209 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
210 | * to extract and print useful information.
211 | */
212 | public static void wtf(String tag, String msg, Throwable tr) {
213 | println(ASSERT, tag, msg, tr);
214 | }
215 |
216 | /**
217 | * Prints a message at ASSERT priority.
218 | *
219 | * @param tag Tag for for the log data. Can be used to organize log statements.
220 | * @param msg The actual message to be logged.
221 | */
222 | public static void wtf(String tag, String msg) {
223 | wtf(tag, msg, null);
224 | }
225 |
226 | /**
227 | * Prints a message at ASSERT priority.
228 | *
229 | * @param tag Tag for for the log data. Can be used to organize log statements.
230 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
231 | * to extract and print useful information.
232 | */
233 | public static void wtf(String tag, Throwable tr) {
234 | wtf(tag, null, tr);
235 | }
236 | }
237 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/common/logger/LogFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 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 |
17 |
18 | package com.example.android.common.logger;
19 |
20 | import android.graphics.Typeface;
21 | import android.os.Build;
22 | import android.os.Bundle;
23 | import androidx.fragment.app.Fragment;
24 | import android.text.Editable;
25 | import android.text.TextWatcher;
26 | import android.view.Gravity;
27 | import android.view.LayoutInflater;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 | import android.widget.ScrollView;
31 |
32 | /**
33 | * Simple fraggment which contains a LogView and uses is to output log data it receives
34 | * through the LogNode interface.
35 | */
36 | public class LogFragment extends Fragment {
37 |
38 | private LogView mLogView;
39 | private ScrollView mScrollView;
40 |
41 | public LogFragment() {}
42 |
43 | @SuppressWarnings("deprecation")
44 | public View inflateViews() {
45 | mScrollView = new ScrollView(getActivity());
46 | ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams(
47 | ViewGroup.LayoutParams.MATCH_PARENT,
48 | ViewGroup.LayoutParams.MATCH_PARENT);
49 | mScrollView.setLayoutParams(scrollParams);
50 |
51 | mLogView = new LogView(getActivity());
52 | ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams);
53 | logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
54 | mLogView.setLayoutParams(logParams);
55 | mLogView.setClickable(true);
56 | mLogView.setFocusable(true);
57 | mLogView.setTypeface(Typeface.MONOSPACE);
58 |
59 | // Want to set padding as 16 dips, setPadding takes pixels. Hooray math!
60 | int paddingDips = 16;
61 | double scale = getResources().getDisplayMetrics().density;
62 | int paddingPixels = (int) ((paddingDips * (scale)) + .5);
63 | mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels);
64 | mLogView.setCompoundDrawablePadding(paddingPixels);
65 |
66 | mLogView.setGravity(Gravity.BOTTOM);
67 | if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
68 | mLogView.setTextAppearance(android.R.style.TextAppearance_Holo_Medium);
69 | } else {
70 | mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium);
71 | }
72 |
73 | mScrollView.addView(mLogView);
74 | return mScrollView;
75 | }
76 |
77 | @Override
78 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
79 | Bundle savedInstanceState) {
80 |
81 | View result = inflateViews();
82 |
83 | mLogView.addTextChangedListener(new TextWatcher() {
84 | @Override
85 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
86 |
87 | @Override
88 | public void onTextChanged(CharSequence s, int start, int before, int count) {}
89 |
90 | @Override
91 | public void afterTextChanged(Editable s) {
92 | mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
93 | }
94 | });
95 | return result;
96 | }
97 |
98 | public LogView getLogView() {
99 | return mLogView;
100 | }
101 | }
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/common/logger/LogNode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 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 | package com.example.android.common.logger;
17 |
18 | /**
19 | * Basic interface for a logging system that can output to one or more targets.
20 | * Note that in addition to classes that will output these logs in some format,
21 | * one can also implement this interface over a filter and insert that in the chain,
22 | * such that no targets further down see certain data, or see manipulated forms of the data.
23 | * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data
24 | * it received to HTML and sent it along to the next node in the chain, without printing it
25 | * anywhere.
26 | */
27 | public interface LogNode {
28 |
29 | /**
30 | * Instructs first LogNode in the list to print the log data provided.
31 | * @param priority Log level of the data being logged. Verbose, Error, etc.
32 | * @param tag Tag for for the log data. Can be used to organize log statements.
33 | * @param msg The actual message to be logged. The actual message to be logged.
34 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
35 | * to extract and print useful information.
36 | */
37 | public void println(int priority, String tag, String msg, Throwable tr);
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/common/logger/LogView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 | package com.example.android.common.logger;
17 |
18 | import android.app.Activity;
19 | import android.content.Context;
20 | import android.util.AttributeSet;
21 | import androidx.appcompat.widget.AppCompatTextView;
22 |
23 | /** Simple TextView which is used to output log data received through the LogNode interface.
24 | */
25 | public class LogView extends AppCompatTextView implements LogNode {
26 |
27 | public LogView(Context context) {
28 | super(context);
29 | }
30 |
31 | public LogView(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | }
34 |
35 | public LogView(Context context, AttributeSet attrs, int defStyle) {
36 | super(context, attrs, defStyle);
37 | }
38 |
39 | /**
40 | * Formats the log data and prints it out to the LogView.
41 | * @param priority Log level of the data being logged. Verbose, Error, etc.
42 | * @param tag Tag for for the log data. Can be used to organize log statements.
43 | * @param msg The actual message to be logged. The actual message to be logged.
44 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
45 | * to extract and print useful information.
46 | */
47 | @Override
48 | public void println(int priority, String tag, String msg, Throwable tr) {
49 |
50 |
51 | String priorityStr = null;
52 |
53 | // For the purposes of this View, we want to print the priority as readable text.
54 | switch(priority) {
55 | case android.util.Log.VERBOSE:
56 | priorityStr = "VERBOSE";
57 | break;
58 | case android.util.Log.DEBUG:
59 | priorityStr = "DEBUG";
60 | break;
61 | case android.util.Log.INFO:
62 | priorityStr = "INFO";
63 | break;
64 | case android.util.Log.WARN:
65 | priorityStr = "WARN";
66 | break;
67 | case android.util.Log.ERROR:
68 | priorityStr = "ERROR";
69 | break;
70 | case android.util.Log.ASSERT:
71 | priorityStr = "ASSERT";
72 | break;
73 | default:
74 | break;
75 | }
76 |
77 | // Handily, the Log class has a facility for converting a stack trace into a usable string.
78 | String exceptionStr = null;
79 | if (tr != null) {
80 | exceptionStr = android.util.Log.getStackTraceString(tr);
81 | }
82 |
83 | // Take the priority, tag, message, and exception, and concatenate as necessary
84 | // into one usable line of text.
85 | final StringBuilder outputBuilder = new StringBuilder();
86 |
87 | String delimiter = "\t";
88 | appendIfNotNull(outputBuilder, priorityStr, delimiter);
89 | appendIfNotNull(outputBuilder, tag, delimiter);
90 | appendIfNotNull(outputBuilder, msg, delimiter);
91 | appendIfNotNull(outputBuilder, exceptionStr, delimiter);
92 |
93 | // In case this was originally called from an AsyncTask or some other off-UI thread,
94 | // make sure the update occurs within the UI thread.
95 | ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() {
96 | @Override
97 | public void run() {
98 | // Display the text we just generated within the LogView.
99 | appendToLog(outputBuilder.toString());
100 | }
101 | })));
102 |
103 | if (mNext != null) {
104 | mNext.println(priority, tag, msg, tr);
105 | }
106 | }
107 |
108 | public LogNode getNext() {
109 | return mNext;
110 | }
111 |
112 | public void setNext(LogNode node) {
113 | mNext = node;
114 | }
115 |
116 | /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since
117 | * the logger takes so many arguments that might be null, this method helps cut out some of the
118 | * agonizing tedium of writing the same 3 lines over and over.
119 | * @param source StringBuilder containing the text to append to.
120 | * @param addStr The String to append
121 | * @param delimiter The String to separate the source and appended strings. A tab or comma,
122 | * for instance.
123 | * @return The fully concatenated String as a StringBuilder
124 | */
125 | private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) {
126 | if (addStr != null) {
127 | if (addStr.length() == 0) {
128 | delimiter = "";
129 | }
130 |
131 | return source.append(addStr).append(delimiter);
132 | }
133 | return source;
134 | }
135 |
136 | // The next LogNode in the chain.
137 | LogNode mNext;
138 |
139 | /** Outputs the string as a new line of log data in the LogView. */
140 | public void appendToLog(String s) {
141 | append("\n" + s);
142 | }
143 |
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/common/logger/LogWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 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 | package com.example.android.common.logger;
17 |
18 | import android.util.Log;
19 |
20 | /**
21 | * Helper class which wraps Android's native Log utility in the Logger interface. This way
22 | * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously.
23 | */
24 | public class LogWrapper implements LogNode {
25 |
26 | // For piping: The next node to receive Log data after this one has done its work.
27 | private LogNode mNext;
28 |
29 | /**
30 | * Returns the next LogNode in the linked list.
31 | */
32 | public LogNode getNext() {
33 | return mNext;
34 | }
35 |
36 | /**
37 | * Sets the LogNode data will be sent to..
38 | */
39 | public void setNext(LogNode node) {
40 | mNext = node;
41 | }
42 |
43 | /**
44 | * Prints data out to the console using Android's native log mechanism.
45 | * @param priority Log level of the data being logged. Verbose, Error, etc.
46 | * @param tag Tag for for the log data. Can be used to organize log statements.
47 | * @param msg The actual message to be logged. The actual message to be logged.
48 | * @param tr If an exception was thrown, this can be sent along for the logging facilities
49 | * to extract and print useful information.
50 | */
51 | @Override
52 | public void println(int priority, String tag, String msg, Throwable tr) {
53 | // There actually are log methods that don't take a msg parameter. For now,
54 | // if that's the case, just convert null to the empty string and move on.
55 | String useMsg = msg;
56 | if (useMsg == null) {
57 | useMsg = "";
58 | }
59 |
60 | // If an exeption was provided, convert that exception to a usable string and attach
61 | // it to the end of the msg method.
62 | if (tr != null) {
63 | msg += "\n" + Log.getStackTraceString(tr);
64 | }
65 |
66 | // This is functionally identical to Log.x(tag, useMsg);
67 | // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
68 | Log.println(priority, tag, useMsg);
69 |
70 | // If this isn't the last node in the chain, move things along.
71 | if (mNext != null) {
72 | mNext.println(priority, tag, msg, tr);
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/common/logger/MessageOnlyLogFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 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 | package com.example.android.common.logger;
17 |
18 | /**
19 | * Simple {@link LogNode} filter, removes everything except the message.
20 | * Useful for situations like on-screen log output where you don't want a lot of metadata displayed,
21 | * just easy-to-read message updates as they're happening.
22 | */
23 | public class MessageOnlyLogFilter implements LogNode {
24 |
25 | LogNode mNext;
26 |
27 | /**
28 | * Takes the "next" LogNode as a parameter, to simplify chaining.
29 | *
30 | * @param next The next LogNode in the pipeline.
31 | */
32 | public MessageOnlyLogFilter(LogNode next) {
33 | mNext = next;
34 | }
35 |
36 | public MessageOnlyLogFilter() {
37 | }
38 |
39 | @Override
40 | public void println(int priority, String tag, String msg, Throwable tr) {
41 | if (mNext != null) {
42 | getNext().println(Log.NONE, null, msg, null);
43 | }
44 | }
45 |
46 | /**
47 | * Returns the next LogNode in the chain.
48 | */
49 | public LogNode getNext() {
50 | return mNext;
51 | }
52 |
53 | /**
54 | * Sets the LogNode data will be sent to..
55 | */
56 | public void setNext(LogNode node) {
57 | mNext = node;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/managedconfigurations/EnterpriseReporter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 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 |
17 | package com.example.android.managedconfigurations
18 |
19 | import android.content.Context
20 | import android.util.Log
21 | import androidx.enterprise.feedback.KeyedAppState
22 | import androidx.enterprise.feedback.KeyedAppStatesCallback
23 | import androidx.enterprise.feedback.KeyedAppStatesCallback.STATUS_EXCEEDED_BUFFER_ERROR
24 | import androidx.enterprise.feedback.KeyedAppStatesCallback.STATUS_SUCCESS
25 | import androidx.enterprise.feedback.KeyedAppStatesCallback.STATUS_TRANSACTION_TOO_LARGE_ERROR
26 | import androidx.enterprise.feedback.KeyedAppStatesCallback.STATUS_UNKNOWN_ERROR
27 | import androidx.enterprise.feedback.KeyedAppStatesReporter
28 |
29 | /**
30 | * Sends feedback to device management apps.
31 | */
32 | fun Context.enterpriseFeedback(
33 | key: String,
34 | message: String,
35 | data: String,
36 | severity: Int = KeyedAppState.SEVERITY_ERROR
37 | ) {
38 | val keyedAppStatesReporter = KeyedAppStatesReporter.create(this)
39 | val keyedAppStateMessage = KeyedAppState.builder()
40 | .setSeverity(severity)
41 | .setKey(key)
42 | .setMessage(message)
43 | .setData(data)
44 | .build()
45 | val list: MutableList = ArrayList()
46 | list.add(keyedAppStateMessage)
47 | keyedAppStatesReporter.setStates(list, Callback())
48 | }
49 |
50 | internal class Callback : KeyedAppStatesCallback {
51 | override fun onResult(state: Int, throwable: Throwable?) {
52 | when (state) {
53 | STATUS_SUCCESS ->
54 | Log.i("ErrorReporter", "KeyedAppStatesCallback status: SUCCESS ")
55 | STATUS_UNKNOWN_ERROR ->
56 | Log.i("ErrorReporter", "KeyedAppStatesCallback status: UNKNOWN_ERROR ")
57 | STATUS_TRANSACTION_TOO_LARGE_ERROR ->
58 | Log.i("ErrorReporter", "KeyedAppStatesCallback status: TRANSACTION_TOO_LARGE_ERROR ")
59 | STATUS_EXCEEDED_BUFFER_ERROR ->
60 | Log.i("ErrorReporter", "KeyedAppStatesCallback status: EXCEEDED_BUFFER_ERROR ")
61 | else ->
62 | Log.i("ErrorReporter", "KeyedAppStatesCallback status: $state ")
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/managedconfigurations/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 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 | package com.example.android.managedconfigurations
17 |
18 | import android.os.Bundle
19 | import android.view.Menu
20 | import android.view.MenuItem
21 | import android.widget.ViewAnimator
22 | import androidx.activity.enableEdgeToEdge
23 | import androidx.core.view.ViewCompat
24 | import androidx.core.view.WindowInsetsCompat
25 | import com.example.android.managedconfigurations.databinding.ActivityMainBinding
26 | import com.example.android.common.activities.SampleActivityBase
27 | import com.example.android.common.logger.Log
28 | import com.example.android.common.logger.LogFragment
29 | import com.example.android.common.logger.LogWrapper
30 | import com.example.android.common.logger.MessageOnlyLogFilter
31 |
32 | /**
33 | * A simple launcher activity containing a summary sample description, sample log and a custom
34 | * [Fragment] which can display a view.
35 | *
36 | *
37 | * For devices with displays with a width of 720dp or greater, the sample log is always visible,
38 | * on other devices it's visibility is controlled by an item on the Action Bar.
39 | */
40 | class MainActivity : SampleActivityBase() {
41 | // Whether the Log Fragment is currently shown
42 | private var logShown = false
43 |
44 | private lateinit var binding: ActivityMainBinding
45 |
46 | override fun onCreate(savedInstanceState: Bundle?) {
47 | super.onCreate(savedInstanceState)
48 | enableEdgeToEdge()
49 | binding = ActivityMainBinding.inflate(layoutInflater)
50 | setContentView(binding.root)
51 | ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
52 | val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
53 | v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
54 | insets
55 | }
56 | if (savedInstanceState == null) {
57 | val transaction = supportFragmentManager.beginTransaction()
58 | val fragment = ManagedConfigurationsFragment()
59 | transaction.replace(R.id.sample_content_fragment, fragment)
60 | transaction.commit()
61 | }
62 | }
63 |
64 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
65 | menuInflater.inflate(R.menu.main, menu)
66 | return true
67 | }
68 |
69 | override fun onPrepareOptionsMenu(menu: Menu): Boolean {
70 | val logToggle = menu.findItem(R.id.menu_toggle_log)
71 | logToggle.isVisible = binding.sampleOutput is ViewAnimator
72 | logToggle.setTitle(if (logShown) R.string.sample_hide_log else R.string.sample_show_log)
73 | return super.onPrepareOptionsMenu(menu)
74 | }
75 |
76 | override fun onOptionsItemSelected(item: MenuItem) =
77 | when (item.itemId) {
78 | R.id.menu_toggle_log -> {
79 | logShown = !logShown
80 | val output = binding.sampleOutput as ViewAnimator
81 | output.displayedChild = if (logShown) {
82 | 1
83 | } else {
84 | 0
85 | }
86 | invalidateOptionsMenu()
87 | true
88 | }
89 | else -> super.onOptionsItemSelected(item)
90 | }
91 |
92 | /**
93 | * Create a chain of targets that will receive log data
94 | */
95 | override fun initializeLogging() {
96 | // Wraps Android's native log framework.
97 | val logWrapper = LogWrapper()
98 | // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
99 | Log.setLogNode(logWrapper)
100 |
101 | // Filter strips out everything except the message text.
102 | val msgFilter = MessageOnlyLogFilter()
103 | logWrapper.next = msgFilter
104 |
105 | // On screen logging via a fragment with a TextView.
106 | val logFragment = supportFragmentManager
107 | .findFragmentById(R.id.log_fragment) as LogFragment?
108 | logFragment?.let {
109 | msgFilter.next = logFragment.logView
110 | Log.i(TAG, "Ready")
111 | }
112 | }
113 |
114 | companion object {
115 | const val TAG = "MainActivity"
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/java/com/example/android/managedconfigurations/ManagedConfigurationsFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 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 | package com.example.android.managedconfigurations
17 |
18 | import android.content.BroadcastReceiver
19 | import android.content.Context
20 | import android.content.Intent
21 | import android.content.IntentFilter
22 | import android.content.RestrictionEntry
23 | import android.content.RestrictionsManager
24 | import android.os.Build
25 | import android.os.Bundle
26 | import android.view.LayoutInflater
27 | import android.view.View
28 | import android.view.ViewGroup
29 | import android.widget.Toast
30 | import androidx.fragment.app.Fragment
31 | import com.example.android.managedconfigurations.databinding.FragmentManagedConfigurationsBinding
32 | import com.example.android.common.logger.Log
33 | import java.lang.StringBuilder
34 |
35 | /**
36 | * Pressing the button on this fragment pops up a simple Toast message. The button is enabled or
37 | * disabled according to the restrictions set by device/profile owner. You can use the
38 | * AppRestrictionEnforcer sample as a profile owner for this.
39 | */
40 | class ManagedConfigurationsFragment : Fragment(), View.OnClickListener {
41 | // Message to show when the button is clicked (String restriction)
42 | private var message: String? = null
43 |
44 | // Observes restriction changes
45 | private var broadcastReceiver: BroadcastReceiver? = null
46 |
47 | private var _binding: FragmentManagedConfigurationsBinding? = null
48 |
49 | // This property is only valid between onCreateView and onDestroyView.
50 | private val binding get() = _binding!!
51 |
52 | override fun onCreateView(
53 | inflater: LayoutInflater,
54 | container: ViewGroup?,
55 | savedInstanceState: Bundle?
56 | ): View {
57 | _binding = FragmentManagedConfigurationsBinding.inflate(inflater, container, false)
58 | return binding.root
59 | }
60 |
61 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
62 | binding.sayHello.setOnClickListener(this)
63 | if (BUNDLE_SUPPORTED) {
64 | binding.yourItems.visibility = View.VISIBLE
65 | } else {
66 | binding.yourItems.visibility = View.GONE
67 | }
68 | }
69 |
70 | override fun onResume() {
71 | super.onResume()
72 | resolveRestrictions()
73 | }
74 |
75 | override fun onStart() {
76 | super.onStart()
77 | broadcastReceiver = object : BroadcastReceiver() {
78 | override fun onReceive(context: Context, intent: Intent) {
79 | resolveRestrictions()
80 | }
81 | }
82 | requireActivity().registerReceiver(
83 | broadcastReceiver,
84 | IntentFilter(Intent.ACTION_APPLICATION_RESTRICTIONS_CHANGED)
85 | )
86 | }
87 |
88 | override fun onStop() {
89 | super.onStop()
90 | if (broadcastReceiver != null) {
91 | requireActivity().unregisterReceiver(broadcastReceiver)
92 | broadcastReceiver = null
93 | }
94 | }
95 |
96 | override fun onDestroyView() {
97 | super.onDestroyView()
98 | _binding = null
99 | }
100 |
101 | private fun resolveRestrictions() {
102 | val manager =
103 | requireActivity().getSystemService(Context.RESTRICTIONS_SERVICE) as RestrictionsManager
104 | val restrictions = manager.applicationRestrictions
105 | val entries = manager.getManifestRestrictions(
106 | requireActivity().applicationContext.packageName
107 | )
108 |
109 | for (entry in entries) {
110 | val key = entry.key
111 | Log.d(TAG, "key: $key")
112 | when (key) {
113 | KEY_CAN_SAY_HELLO -> {
114 | updateCanSayHello(entry, restrictions)
115 | }
116 | KEY_MESSAGE -> {
117 | updateMessage(entry, restrictions)
118 | }
119 | KEY_NUMBER -> {
120 | updateNumber(entry, restrictions)
121 | }
122 | KEY_RANK -> {
123 | updateRank(entry, restrictions)
124 | }
125 | KEY_APPROVALS -> {
126 | updateApprovals(entry, restrictions)
127 | }
128 | KEY_ITEMS -> {
129 | updateItems(restrictions)
130 | }
131 | }
132 | }
133 | }
134 |
135 | private fun updateCanSayHello(entry: RestrictionEntry, restrictions: Bundle?) {
136 | val canSayHello =
137 | if (restrictions == null || !restrictions.containsKey(KEY_CAN_SAY_HELLO)) {
138 | entry.selectedState
139 | } else {
140 | restrictions.getBoolean(KEY_CAN_SAY_HELLO)
141 | }
142 | activity?.enterpriseFeedback(KEY_CAN_SAY_HELLO, "Value is $canSayHello", "$canSayHello")
143 | binding.sayHello.setText(
144 | if (canSayHello) {
145 | R.string.explanation_can_say_hello_true
146 | } else {
147 | R.string.explanation_can_say_hello_false
148 | }
149 | )
150 | binding.sayHello.isEnabled = canSayHello
151 | }
152 |
153 | private fun updateMessage(entry: RestrictionEntry, restrictions: Bundle?) {
154 | message =
155 | if (restrictions == null || !restrictions.containsKey(KEY_MESSAGE)) {
156 | entry.selectedString
157 | } else {
158 | restrictions.getString(KEY_MESSAGE)
159 | }
160 | activity?.enterpriseFeedback(KEY_MESSAGE, "Value is $message", "$message")
161 | }
162 |
163 | private fun updateNumber(entry: RestrictionEntry, restrictions: Bundle?) {
164 | val number = if (restrictions == null || !restrictions.containsKey(KEY_NUMBER)) {
165 | entry.intValue
166 | } else {
167 | restrictions.getInt(KEY_NUMBER)
168 | }
169 | binding.yourNumber.text = getString(R.string.your_number, number)
170 | }
171 |
172 | private fun updateRank(entry: RestrictionEntry, restrictions: Bundle?) {
173 | val rank = if (restrictions == null || !restrictions.containsKey(KEY_RANK)) {
174 | entry.selectedString
175 | } else {
176 | restrictions.getString(KEY_RANK)
177 | }
178 | binding.yourRank.text = getString(R.string.your_rank, rank)
179 | }
180 |
181 | private fun updateApprovals(entry: RestrictionEntry, restrictions: Bundle?) {
182 | val approvals = if (restrictions == null || !restrictions.containsKey(KEY_APPROVALS)) {
183 | entry.allSelectedStrings
184 | } else {
185 | restrictions.getStringArray(KEY_APPROVALS)
186 | }
187 | val text: String = if (approvals.isNullOrEmpty()) {
188 | getString(R.string.none)
189 | } else {
190 | approvals.joinToString(", ")
191 | }
192 | binding.approvalsYouHave.text = getString(R.string.approvals_you_have, text)
193 | }
194 |
195 | private fun updateItems(restrictions: Bundle?) {
196 | if (!BUNDLE_SUPPORTED) {
197 | return
198 | }
199 | val builder = StringBuilder()
200 | if (restrictions != null) {
201 | val parcelables = restrictions.getParcelableArray(KEY_ITEMS)
202 | if (!parcelables.isNullOrEmpty()) {
203 | val items = arrayOfNulls(parcelables.size)
204 | for (i in parcelables.indices) {
205 | items[i] = parcelables[i] as Bundle
206 | }
207 | var first = true
208 | for (item in items) {
209 | if (!item!!.containsKey(KEY_ITEM_KEY) || !item.containsKey(KEY_ITEM_VALUE)) {
210 | continue
211 | }
212 | if (first) {
213 | first = false
214 | } else {
215 | builder.append(", ")
216 | }
217 | builder.append(item.getString(KEY_ITEM_KEY))
218 | builder.append(":")
219 | builder.append(item.getString(KEY_ITEM_VALUE))
220 | }
221 | } else {
222 | builder.append(getString(R.string.none))
223 | }
224 | } else {
225 | builder.append(getString(R.string.none))
226 | }
227 | binding.yourItems.text = getString(R.string.your_items, builder)
228 | }
229 |
230 | override fun onClick(view: View) {
231 | when (view.id) {
232 | R.id.say_hello -> {
233 | Toast.makeText(
234 | activity,
235 | getString(R.string.message, message),
236 | Toast.LENGTH_SHORT
237 | ).show()
238 | }
239 | }
240 | }
241 |
242 | companion object {
243 | // Tag for the logger
244 | private const val TAG = "ManagedConfigurations"
245 | private const val KEY_CAN_SAY_HELLO = "can_say_hello"
246 | private const val KEY_MESSAGE = "message"
247 | private const val KEY_NUMBER = "number"
248 | private const val KEY_RANK = "rank"
249 | private const val KEY_APPROVALS = "approvals"
250 | private const val KEY_ITEMS = "items"
251 | private const val KEY_ITEM_KEY = "key"
252 | private const val KEY_ITEM_VALUE = "value"
253 | private val BUNDLE_SUPPORTED = Build.VERSION.SDK_INT >= 23
254 | }
255 | }
256 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/drawable-hdpi/tile.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/app/src/main/res/drawable-hdpi/tile.9.png
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/layout-w720dp/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
30 |
31 |
35 |
36 |
45 |
46 |
47 |
51 |
52 |
58 |
59 |
60 |
61 |
65 |
66 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
29 |
30 |
34 |
35 |
44 |
45 |
46 |
51 |
52 |
53 |
54 |
58 |
59 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/layout/fragment_managed_configurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
21 |
22 |
27 |
28 |
34 |
35 |
42 |
43 |
51 |
52 |
60 |
61 |
69 |
70 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
24 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 | @dimen/margin_huge
22 | @dimen/margin_medium
23 |
24 |
25 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/values-sw600dp/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 | 4dp
22 | 8dp
23 | 16dp
24 | 32dp
25 | 64dp
26 |
27 |
28 |
29 | @dimen/margin_medium
30 | @dimen/margin_medium
31 |
32 |
33 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/values/restriction_values.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 | Can say hello
21 | Whether the app can say hello to the user
22 | false
23 |
24 |
25 | Message
26 | A message string to show
27 | Hello!
28 |
29 |
30 | Number
31 | Sample integer value
32 | 32582657
33 |
34 |
35 | Rank
36 | Rank of the user
37 | Apprentice
38 | Intermediate
39 | Master
40 |
41 | @string/entry_rank_apprentice
42 | @string/entry_rank_intermediate
43 | @string/entry_rank_master
44 |
45 |
46 | apprentice
47 | intermediate
48 | master
49 |
50 | apprentice
51 |
52 |
53 | Approvals
54 | Approvals
55 | Read
56 | Write
57 | Execute
58 |
59 | @string/entry_approvals_read
60 | @string/entry_approvals_write
61 | @string/entry_approvals_execute
62 |
63 |
64 | read
65 | write
66 | execute
67 |
68 |
69 |
70 |
71 |
72 |
73 | Secret code
74 | This restriction is hidden and will not be shown to the administrator.
75 | (Hidden restriction must have some default value)
76 |
77 |
78 | Sample profile
79 | Profile
80 |
81 | John
82 | The name of this person
83 | Name
84 |
85 | 25
86 | The age of this person
87 | Age
88 |
89 |
90 | Sample items
91 | Items
92 | Item
93 | Key
94 | Value
95 |
96 |
97 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 | ManagedConfiguration
20 |
21 |
31 |
32 | Show Log
33 | Hide Log
34 | I can say hello to you.
35 | I am restricted from saying hello to you.
36 | Say hello
37 | All I can say is \"%s\".
38 |
39 | Your number: %d
40 | Your rank: %s
41 | Approvals you have: %s
42 | none
43 | Your items: %s
44 |
45 |
46 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
28 |
29 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/ManagedConfigurations/app/src/main/res/xml/app_restrictions.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
23 |
24 |
25 |
31 |
32 |
33 |
39 |
40 |
41 |
47 |
48 |
49 |
57 |
58 |
59 |
67 |
68 |
69 |
75 |
76 |
77 |
82 |
83 |
87 |
91 |
95 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/ManagedConfigurations/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Google LLC
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 |
17 | plugins {
18 | alias(libs.plugins.android.application) apply false
19 | alias(libs.plugins.kotlin.android) apply false
20 | }
21 |
--------------------------------------------------------------------------------
/ManagedConfigurations/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. For more details, visit
12 | # https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/ManagedConfigurations/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | # Copyright 2025 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | [versions]
16 | agp = "8.9.2"
17 | kotlin = "2.1.0"
18 | coreKtx = "1.16.0"
19 | junit = "4.13.2"
20 | junitVersion = "1.2.1"
21 | espressoCore = "3.6.1"
22 | appcompat = "1.7.0"
23 | material = "1.12.0"
24 | activity = "1.10.1"
25 | constraintlayout = "2.2.1"
26 | enterprise = "1.1.0"
27 |
28 | [libraries]
29 | androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
30 | junit = { group = "junit", name = "junit", version.ref = "junit" }
31 | androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
32 | androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
33 | androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
34 | material = { group = "com.google.android.material", name = "material", version.ref = "material" }
35 | androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
36 | androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
37 | jetbrains-kotlin-stdlib-jdk7 = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk7", version.ref = "kotlin" }
38 | androidx-enterprise-feedback = { group = "androidx.enterprise", name = "enterprise-feedback", version.ref = "enterprise" }
39 | androidx-enterprise-feedback-testing = { group = "androidx.enterprise", name = "enterprise-feedback-testing", version.ref = "enterprise" }
40 |
41 | [plugins]
42 | android-application = { id = "com.android.application", version.ref = "agp" }
43 | kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
44 |
--------------------------------------------------------------------------------
/ManagedConfigurations/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/ManagedConfigurations/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 24 15:13:10 JST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/ManagedConfigurations/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/ManagedConfigurations/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/ManagedConfigurations/screenshots/app_feedback.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/screenshots/app_feedback.gif
--------------------------------------------------------------------------------
/ManagedConfigurations/screenshots/big_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/screenshots/big_icon.png
--------------------------------------------------------------------------------
/ManagedConfigurations/screenshots/main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/screenshots/main.png
--------------------------------------------------------------------------------
/ManagedConfigurations/screenshots/setup_testdpc.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/screenshots/setup_testdpc.gif
--------------------------------------------------------------------------------
/ManagedConfigurations/screenshots/update_managed_configurations.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/ManagedConfigurations/screenshots/update_managed_configurations.gif
--------------------------------------------------------------------------------
/ManagedConfigurations/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google {
4 | content {
5 | includeGroupByRegex("com\\.android.*")
6 | includeGroupByRegex("com\\.google.*")
7 | includeGroupByRegex("androidx.*")
8 | }
9 | }
10 | mavenCentral()
11 | gradlePluginPortal()
12 | }
13 | }
14 | dependencyResolutionManagement {
15 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
16 | repositories {
17 | google()
18 | mavenCentral()
19 | }
20 | }
21 |
22 | rootProject.name = "Managed Configuration"
23 | include(":app")
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android Enterprise Samples Repository
2 | =====================================
3 |
4 | This repository contains a set of individual Android Studio projects to help you get
5 | started writing/understanding Android Enterprise features.
6 |
--------------------------------------------------------------------------------
/Work-profile-codelab/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local
4 | /.idea/*
5 | !/.idea/runConfigurations/App.xml
6 | .DS_Store
7 | build/
8 | /captures
9 | .externalNativeBuild
10 | local.properties
11 |
--------------------------------------------------------------------------------
/Work-profile-codelab/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2014 The Android Open Source Project
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Work-profile-codelab/README.md:
--------------------------------------------------------------------------------
1 | # Codelab: Build an app that runs on a work profile
2 | Sample app describe in the [Build an app that runs on a work profile][1] codelab.
3 |
4 | Pre-requisites
5 | --------------
6 |
7 | * Android Studio Chipmunk (2021.2.1 Patch 1) or later and you know how to use it.
8 |
9 | * Make sure Android Studio is updated, as well as your SDK and Gradle.
10 | Otherwise, you may have to wait for a while until all the updates are done.
11 |
12 | * A device or emulator that runs API level 29+
13 |
14 | You need to be solidly familiar with the Kotlin programming language,
15 | object-oriented design concepts, and Android Development Fundamentals.
16 |
17 | Getting Started
18 | ---------------
19 |
20 | 1. [Install Android Studio][2],
21 | if you don't already have it.
22 | 2. Download the sample.
23 | 2. Import the sample into Android Studio.
24 | 3. Build and run the sample.
25 |
26 | [1]: https://developer.android.com/codelabs/work-profile-apps
27 | [2]: https://developer.android.com/studio/install.html
28 |
29 | License
30 | -------
31 |
32 | Copyright 2020 Google, Inc.
33 |
34 | All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav
35 | and *.ogg) are licensed under the CC BY 4.0 license. All other files are
36 | licensed under the Apache 2 license.
37 |
38 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
39 | license agreements. See the LICENSE file distributed with this work for
40 | additional information regarding copyright ownership. The ASF licenses this
41 | file to you under the Apache License, Version 2.0 (the "License"); you may not
42 | use this file except in compliance with the License. You may obtain a copy of
43 | the License at
44 |
45 | http://www.apache.org/licenses/LICENSE-2.0
46 |
47 | Unless required by applicable law or agreed to in writing, software
48 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
49 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
50 | License for the specific language governing permissions and limitations under
51 | the License.
52 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | plugins {
18 | alias(libs.plugins.android.application)
19 | alias(libs.plugins.kotlin.android)
20 | }
21 |
22 | android {
23 | namespace = "com.example.workprofile"
24 | compileSdk = 35
25 |
26 | defaultConfig {
27 | applicationId = "com.example.workprofile"
28 | minSdk = 29
29 | targetSdk = 35
30 | versionCode = 1
31 | versionName = "1.0"
32 |
33 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
34 | }
35 |
36 | buildTypes {
37 | release {
38 | isMinifyEnabled = false
39 | proguardFiles(
40 | getDefaultProguardFile("proguard-android-optimize.txt"),
41 | "proguard-rules.pro"
42 | )
43 | }
44 | }
45 | compileOptions {
46 | sourceCompatibility = JavaVersion.VERSION_11
47 | targetCompatibility = JavaVersion.VERSION_11
48 | }
49 | kotlinOptions {
50 | jvmTarget = "11"
51 | }
52 | buildFeatures {
53 | viewBinding = true
54 | }
55 | }
56 |
57 | dependencies {
58 | implementation(libs.androidx.core.ktx)
59 | implementation(libs.androidx.appcompat)
60 | implementation(libs.material)
61 | implementation(libs.androidx.activity)
62 | implementation(libs.androidx.constraintlayout)
63 | implementation(libs.jetbrains.kotlin.stdlib.jdk7)
64 | implementation(libs.androidx.recyclerview)
65 | // For testing enterprise feedback in isolation
66 | testImplementation(libs.junit)
67 | androidTestImplementation(libs.androidx.junit)
68 | androidTestImplementation(libs.androidx.espresso.core)
69 | }
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class contact to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file contact.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/androidTest/java/com/example/workprofile/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | package com.example.workprofile
18 |
19 | import androidx.test.ext.junit.runners.AndroidJUnit4
20 | import androidx.test.platform.app.InstrumentationRegistry
21 | import org.junit.Assert.assertEquals
22 | import org.junit.Test
23 | import org.junit.runner.RunWith
24 |
25 | /**
26 | * Instrumented test, which will execute on an Android device.
27 | *
28 | * See [testing documentation](http://d.android.com/tools/testing).
29 | */
30 | @RunWith(AndroidJUnit4::class)
31 | class ExampleInstrumentedTest {
32 | @Test
33 | fun useAppContext() {
34 | // Context of the app under test.
35 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
36 | assertEquals("com.example.workprofile", appContext.packageName)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
22 |
23 |
31 |
32 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/java/com/example/workprofile/ContactsAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | package com.example.workprofile
18 |
19 | import android.view.LayoutInflater
20 | import android.view.View
21 | import android.view.ViewGroup
22 | import android.widget.TextView
23 | import androidx.recyclerview.widget.RecyclerView
24 |
25 | data class Contact(val name: String, val isWork: Boolean)
26 |
27 | class ContactsAdapter(private val contactList: MutableList) :
28 | RecyclerView.Adapter() {
29 |
30 | override fun onCreateViewHolder(viewGroup: ViewGroup, position: Int): ContactViewHolder {
31 | val view = LayoutInflater.from(viewGroup.context)
32 | .inflate(R.layout.contact_item_layout, viewGroup, false)
33 | return ContactViewHolder(view)
34 | }
35 |
36 | override fun onBindViewHolder(holder: ContactViewHolder, position: Int) {
37 | val contact = contactList[position]
38 | holder.contact?.let {
39 | it.text = contact.name
40 | it.setCompoundDrawablesRelativeWithIntrinsicBounds(
41 | it.resources?.getDrawable(
42 | when (contact.isWork) {
43 | true -> R.drawable.ic_person_primary_40dp
44 | false -> R.drawable.ic_person_green_40dp
45 | },
46 | null
47 | ),
48 | null,
49 | null,
50 | null
51 | )
52 | }
53 | }
54 |
55 | override fun getItemCount(): Int = contactList.size
56 |
57 | class ContactViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
58 | var contact: TextView? = itemView.findViewById(R.id.contact_name_tv) as TextView
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/java/com/example/workprofile/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | package com.example.workprofile
18 |
19 | import android.Manifest
20 | import android.content.pm.CrossProfileApps
21 | import android.content.pm.PackageManager
22 | import android.database.Cursor
23 | import android.net.Uri
24 | import android.os.Bundle
25 | import android.provider.ContactsContract
26 | import android.widget.Toast
27 | import androidx.appcompat.app.AppCompatActivity
28 | import androidx.activity.enableEdgeToEdge
29 | import androidx.core.view.ViewCompat
30 | import androidx.core.view.WindowInsetsCompat
31 | import androidx.loader.app.LoaderManager
32 | import androidx.loader.content.CursorLoader
33 | import androidx.loader.content.Loader
34 | import androidx.recyclerview.widget.LinearLayoutManager
35 | import androidx.recyclerview.widget.RecyclerView
36 | import com.example.workprofile.databinding.ActivityMainBinding
37 |
38 | const val PERMISSIONS_REQUEST_READ_CONTACTS = 1
39 | const val PERSONAL_CONTACTS_LOADER_ID = 0
40 | const val WORK_CONTACTS_LOADER_ID = 1
41 |
42 | class MainActivity : AppCompatActivity(), LoaderManager.LoaderCallbacks {
43 | private lateinit var viewAdapter: RecyclerView.Adapter<*>
44 | private lateinit var binding: ActivityMainBinding
45 | private var contacts: MutableList = ArrayList()
46 |
47 | override fun onCreate(savedInstanceState: Bundle?) {
48 | super.onCreate(savedInstanceState)
49 | binding = ActivityMainBinding.inflate(layoutInflater)
50 | setContentView(binding.root)
51 | enableEdgeToEdge()
52 | ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
53 | val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
54 | v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
55 | insets
56 | }
57 |
58 | val viewManager = LinearLayoutManager(this)
59 | viewAdapter = ContactsAdapter(contacts)
60 | binding.contactsRv.apply {
61 | setHasFixedSize(true)
62 | layoutManager = viewManager
63 | adapter = viewAdapter
64 | }
65 | val permission = checkSelfPermission(Manifest.permission.READ_CONTACTS)
66 | if (permission != PackageManager.PERMISSION_GRANTED) {
67 | requestPermissions(
68 | arrayOf(Manifest.permission.READ_CONTACTS),
69 | PERMISSIONS_REQUEST_READ_CONTACTS
70 | )
71 | } else {
72 | initLoaders()
73 | }
74 |
75 | val crossProfileApps = getSystemService(CrossProfileApps::class.java)
76 | val userHandles = crossProfileApps.targetUserProfiles
77 | val label = crossProfileApps.getProfileSwitchingLabel(userHandles.first())
78 | binding.button.apply {
79 | text = label
80 | setOnClickListener {
81 | crossProfileApps.startMainActivity(
82 | componentName,
83 | userHandles.first()
84 | )
85 | }
86 | }
87 | }
88 |
89 | override fun onRequestPermissionsResult(
90 | requestCode: Int,
91 | permissions: Array,
92 | grantResults: IntArray
93 | ) {
94 | super.onRequestPermissionsResult(requestCode, permissions, grantResults)
95 | if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS) {
96 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
97 | initLoaders()
98 | } else {
99 | Toast.makeText(
100 | this,
101 | "Permission must be granted in order to display contacts information",
102 | Toast.LENGTH_LONG
103 | ).show()
104 | }
105 | }
106 | }
107 |
108 | private fun initLoaders() {
109 | LoaderManager.getInstance(this).initLoader(PERSONAL_CONTACTS_LOADER_ID, null, this)
110 | LoaderManager.getInstance(this).initLoader(WORK_CONTACTS_LOADER_ID, null, this)
111 | }
112 |
113 | override fun onCreateLoader(id: Int, args: Bundle?): Loader {
114 | val nameFilter = Uri.encode("a") // names that start with a
115 | val contentURI = when (id) {
116 | PERSONAL_CONTACTS_LOADER_ID -> ContactsContract.Contacts.CONTENT_URI
117 | else -> {
118 | ContactsContract.Contacts.ENTERPRISE_CONTENT_FILTER_URI
119 | .buildUpon()
120 | .appendPath(nameFilter)
121 | .appendQueryParameter(
122 | ContactsContract.DIRECTORY_PARAM_KEY,
123 | ContactsContract.Directory.ENTERPRISE_DEFAULT.toString()
124 | )
125 | .build()
126 | }
127 | }
128 | return CursorLoader(
129 | this,
130 | contentURI,
131 | arrayOf(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY),
132 | null,
133 | null,
134 | null
135 | )
136 | }
137 |
138 | override fun onLoadFinished(loader: Loader, data: Cursor?) {
139 | data?.let {
140 | if (!data.isClosed && data.count > 0) {
141 | while (data.moveToNext()) {
142 | val name = data.getString(0) ?: ""
143 | println(name)
144 | val contact = Contact(name, loader.id == 1)
145 | contacts.add(contact)
146 | }
147 | }
148 | viewAdapter.notifyDataSetChanged()
149 | data.close()
150 | }
151 | }
152 |
153 | override fun onLoaderReset(loader: Loader) {
154 | }
155 | }
156 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/drawable-v24/ic_person_primary_40dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/drawable/ic_person_green_40dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
26 |
27 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/layout/contact_item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-finished/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Work Profile Demo
3 |
4 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-finished/src/test/java/com/example/workprofile/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | package com.example.workprofile
18 |
19 | import org.junit.Assert.assertEquals
20 | import org.junit.Test
21 |
22 | /**
23 | * Example local unit test, which will execute on the development machine (host).
24 | *
25 | * See [testing documentation](http://d.android.com/tools/testing).
26 | */
27 | class ExampleUnitTest {
28 | @Test
29 | fun addition_isCorrect() {
30 | assertEquals(4, 2 + 2)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | plugins {
18 | alias(libs.plugins.android.application)
19 | alias(libs.plugins.kotlin.android)
20 | }
21 |
22 | android {
23 | namespace = "com.example.workprofile"
24 | compileSdk = 35
25 |
26 | defaultConfig {
27 | applicationId = "com.example.workprofile"
28 | minSdk = 29
29 | targetSdk = 35
30 | versionCode = 1
31 | versionName = "1.0"
32 |
33 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
34 | }
35 |
36 | buildTypes {
37 | release {
38 | isMinifyEnabled = false
39 | proguardFiles(
40 | getDefaultProguardFile("proguard-android-optimize.txt"),
41 | "proguard-rules.pro"
42 | )
43 | }
44 | }
45 | compileOptions {
46 | sourceCompatibility = JavaVersion.VERSION_11
47 | targetCompatibility = JavaVersion.VERSION_11
48 | }
49 | kotlinOptions {
50 | jvmTarget = "11"
51 | }
52 | buildFeatures {
53 | viewBinding = true
54 | }
55 | }
56 |
57 | dependencies {
58 | implementation(libs.androidx.core.ktx)
59 | implementation(libs.androidx.appcompat)
60 | implementation(libs.material)
61 | implementation(libs.androidx.activity)
62 | implementation(libs.androidx.constraintlayout)
63 | implementation(libs.jetbrains.kotlin.stdlib.jdk7)
64 | implementation(libs.androidx.recyclerview)
65 | // For testing enterprise feedback in isolation
66 | testImplementation(libs.junit)
67 | androidTestImplementation(libs.androidx.junit)
68 | androidTestImplementation(libs.androidx.espresso.core)
69 | }
70 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class contact to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file contact.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/androidTest/java/com/example/workprofile/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | package com.example.workprofile
18 |
19 | import androidx.test.ext.junit.runners.AndroidJUnit4
20 | import androidx.test.platform.app.InstrumentationRegistry
21 | import org.junit.Assert.assertEquals
22 | import org.junit.Test
23 | import org.junit.runner.RunWith
24 |
25 | /**
26 | * Instrumented test, which will execute on an Android device.
27 | *
28 | * See [testing documentation](http://d.android.com/tools/testing).
29 | */
30 | @RunWith(AndroidJUnit4::class)
31 | class ExampleInstrumentedTest {
32 | @Test
33 | fun useAppContext() {
34 | // Context of the app under test.
35 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
36 | assertEquals("com.example.workprofile", appContext.packageName)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
20 |
21 |
22 |
23 |
31 |
32 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/java/com/example/workprofile/ContactsAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | package com.example.workprofile
18 |
19 | import android.view.LayoutInflater
20 | import android.view.View
21 | import android.view.ViewGroup
22 | import android.widget.TextView
23 | import androidx.recyclerview.widget.RecyclerView
24 |
25 | data class Contact(val name: String, val isWork: Boolean)
26 |
27 | class ContactsAdapter(private val contactList: MutableList) :
28 | RecyclerView.Adapter() {
29 |
30 | override fun onCreateViewHolder(viewGroup: ViewGroup, position: Int): ContactViewHolder {
31 | val view = LayoutInflater.from(viewGroup.context)
32 | .inflate(R.layout.contact_item_layout, viewGroup, false)
33 | return ContactViewHolder(view)
34 | }
35 |
36 | override fun onBindViewHolder(holder: ContactViewHolder, position: Int) {
37 | val contact = contactList[position]
38 | holder.contact?.let {
39 | it.text = contact.name
40 | it.setCompoundDrawablesRelativeWithIntrinsicBounds(
41 | it.resources?.getDrawable(
42 | when (contact.isWork) {
43 | true -> R.drawable.ic_person_primary_40dp
44 | false -> R.drawable.ic_person_green_40dp
45 | },
46 | null
47 | ),
48 | null,
49 | null,
50 | null
51 | )
52 | }
53 | }
54 |
55 | override fun getItemCount(): Int = contactList.size
56 |
57 | class ContactViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
58 | var contact: TextView? = itemView.findViewById(R.id.contact_name_tv) as TextView
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/java/com/example/workprofile/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | package com.example.workprofile
18 |
19 | import android.Manifest
20 | import android.annotation.SuppressLint
21 | import android.content.pm.PackageManager
22 | import android.database.Cursor
23 | import android.os.Bundle
24 | import android.provider.ContactsContract
25 | import android.widget.Toast
26 | import androidx.activity.enableEdgeToEdge
27 | import androidx.core.view.ViewCompat
28 | import androidx.core.view.WindowInsetsCompat
29 | import androidx.appcompat.app.AppCompatActivity
30 | import androidx.loader.app.LoaderManager
31 | import androidx.loader.content.CursorLoader
32 | import androidx.loader.content.Loader
33 | import androidx.recyclerview.widget.LinearLayoutManager
34 | import androidx.recyclerview.widget.RecyclerView
35 | import com.example.workprofile.databinding.ActivityMainBinding
36 |
37 | const val PERMISSIONS_REQUEST_READ_CONTACTS = 1
38 | const val PERSONAL_CONTACTS_LOADER_ID = 0
39 |
40 | class MainActivity : AppCompatActivity(), LoaderManager.LoaderCallbacks {
41 | private lateinit var viewAdapter: RecyclerView.Adapter<*>
42 | private lateinit var binding: ActivityMainBinding
43 | private var contacts: MutableList = ArrayList()
44 |
45 | override fun onCreate(savedInstanceState: Bundle?) {
46 | super.onCreate(savedInstanceState)
47 | enableEdgeToEdge()
48 | binding = ActivityMainBinding.inflate(layoutInflater)
49 | setContentView(binding.root)
50 | ViewCompat.setOnApplyWindowInsetsListener(binding.root) { v, insets ->
51 | val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
52 | v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
53 | insets
54 | }
55 |
56 | val viewManager = LinearLayoutManager(this)
57 | viewAdapter = ContactsAdapter(contacts)
58 | binding.contactsRv.apply {
59 | setHasFixedSize(true)
60 | layoutManager = viewManager
61 | adapter = viewAdapter
62 | }
63 | val permission = checkSelfPermission(Manifest.permission.READ_CONTACTS)
64 | if (permission != PackageManager.PERMISSION_GRANTED) {
65 | requestPermissions(
66 | arrayOf(Manifest.permission.READ_CONTACTS),
67 | PERMISSIONS_REQUEST_READ_CONTACTS
68 | )
69 | } else {
70 | initLoaders()
71 | }
72 | }
73 |
74 | override fun onRequestPermissionsResult(
75 | requestCode: Int,
76 | permissions: Array,
77 | grantResults: IntArray
78 | ) {
79 | super.onRequestPermissionsResult(requestCode, permissions, grantResults)
80 | if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS) {
81 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
82 | initLoaders()
83 | } else {
84 | Toast.makeText(
85 | this,
86 | "Permission must be granted in order to display contacts information",
87 | Toast.LENGTH_LONG
88 | ).show()
89 | }
90 | }
91 | }
92 |
93 | private fun initLoaders() {
94 | LoaderManager.getInstance(this).initLoader(PERSONAL_CONTACTS_LOADER_ID, null, this)
95 | }
96 |
97 | override fun onCreateLoader(id: Int, args: Bundle?): Loader {
98 | val contentURI = ContactsContract.Contacts.CONTENT_URI
99 | return CursorLoader(
100 | this,
101 | contentURI,
102 | arrayOf(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY),
103 | null,
104 | null,
105 | null
106 | )
107 | }
108 |
109 | @SuppressLint("NotifyDataSetChanged")
110 | override fun onLoadFinished(loader: Loader, data: Cursor?) {
111 | data?.let {
112 | if (!data.isClosed && data.count > 0) {
113 | while (data.moveToNext()) {
114 | val name = data.getString(0) ?: ""
115 | println(name)
116 | val contact = Contact(name, loader.id == 1)
117 | contacts.add(contact)
118 | }
119 | }
120 | viewAdapter.notifyDataSetChanged()
121 | data.close()
122 | }
123 | }
124 |
125 | override fun onLoaderReset(loader: Loader) {
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/drawable-v24/ic_person_primary_40dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/drawable/ic_person_green_40dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/layout/contact_item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/app-starter/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Work Profile Demo
3 |
4 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Work-profile-codelab/app-starter/src/test/java/com/example/workprofile/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | package com.example.workprofile
18 |
19 | import org.junit.Assert.assertEquals
20 | import org.junit.Test
21 |
22 | /**
23 | * Example local unit test, which will execute on the development machine (host).
24 | *
25 | * See [testing documentation](http://d.android.com/tools/testing).
26 | */
27 | class ExampleUnitTest {
28 | @Test
29 | fun addition_isCorrect() {
30 | assertEquals(4, 2 + 2)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Work-profile-codelab/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 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 |
17 | plugins {
18 | alias(libs.plugins.android.application) apply false
19 | alias(libs.plugins.kotlin.android) apply false
20 | }
21 |
--------------------------------------------------------------------------------
/Work-profile-codelab/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. For more details, visit
12 | # https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/Work-profile-codelab/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | # Copyright 2025 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | [versions]
16 | agp = "8.8.0"
17 | kotlin = "2.0.21"
18 | coreKtx = "1.15.0"
19 | junit = "4.13.2"
20 | junitVersion = "1.2.1"
21 | espressoCore = "3.6.1"
22 | appcompat = "1.7.0"
23 | material = "1.12.0"
24 | activity = "1.9.3"
25 | constraintlayout = "2.2.0"
26 | recyclerview = "1.3.2"
27 |
28 | [libraries]
29 | androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
30 | junit = { group = "junit", name = "junit", version.ref = "junit" }
31 | androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
32 | androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
33 | androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
34 | material = { group = "com.google.android.material", name = "material", version.ref = "material" }
35 | androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
36 | androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
37 | jetbrains-kotlin-stdlib-jdk7 = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk7", version.ref = "kotlin" }
38 | androidx-recyclerview = { group = "androidx.recyclerview", name="recyclerview", version.ref = "recyclerview" }
39 |
40 | [plugins]
41 | android-application = { id = "com.android.application", version.ref = "agp" }
42 | kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
43 |
--------------------------------------------------------------------------------
/Work-profile-codelab/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/enterprise-samples/d3ac0d67c0c73d487b350d811da04913d546e0f6/Work-profile-codelab/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Work-profile-codelab/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue May 10 13:45:28 JST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
--------------------------------------------------------------------------------
/Work-profile-codelab/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/Work-profile-codelab/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/Work-profile-codelab/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | include(":app-starter")
2 | //include (":app-finished")
3 | rootProject.name = "android-work-profile"
4 |
5 | pluginManagement {
6 | repositories {
7 | google {
8 | content {
9 | includeGroupByRegex("com\\.android.*")
10 | includeGroupByRegex("com\\.google.*")
11 | includeGroupByRegex("androidx.*")
12 | }
13 | }
14 | mavenCentral()
15 | gradlePluginPortal()
16 | }
17 | }
18 | dependencyResolutionManagement {
19 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
20 | repositories {
21 | google()
22 | mavenCentral()
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "local>android/.github:renovate-config"
5 | ]
6 | }
7 |
--------------------------------------------------------------------------------