• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.base.compat;
6 
7 import android.content.ClipboardManager;
8 import android.content.pm.PackageInfo;
9 import android.content.pm.PackageManager;
10 import android.location.LocationManager;
11 import android.net.LinkProperties;
12 import android.os.Build;
13 import android.os.LocaleList;
14 import android.telephony.SignalStrength;
15 import android.telephony.TelephonyManager;
16 import android.view.textclassifier.TextClassifier;
17 import android.view.textclassifier.TextSelection;
18 
19 import androidx.annotation.RequiresApi;
20 
21 /**
22  * Utility class to use new APIs that were added in P (API level 28). These need to exist in a
23  * separate class so that Android framework can successfully verify classes without
24  * encountering the new APIs.
25  */
26 @RequiresApi(Build.VERSION_CODES.P)
27 public final class ApiHelperForP {
ApiHelperForP()28     private ApiHelperForP() {}
29 
30     /** See {@link LinkProperties#isPrivateDnsActive() }. */
isPrivateDnsActive(LinkProperties linkProperties)31     public static boolean isPrivateDnsActive(LinkProperties linkProperties) {
32         return linkProperties.isPrivateDnsActive();
33     }
34 
35     /** See {@link LinkProperties#getPrivateDnsServerName() }. */
getPrivateDnsServerName(LinkProperties linkProperties)36     public static String getPrivateDnsServerName(LinkProperties linkProperties) {
37         return linkProperties.getPrivateDnsServerName();
38     }
39 
40     /** See {@link PackageInfo#getLongVersionCode() }. */
getLongVersionCode(PackageInfo packageInfo)41     public static long getLongVersionCode(PackageInfo packageInfo) {
42         return packageInfo.getLongVersionCode();
43     }
44 
45     /** See {@link LocationManager#isLocationEnabled() }. */
isLocationEnabled(LocationManager locationManager)46     public static boolean isLocationEnabled(LocationManager locationManager) {
47         return locationManager.isLocationEnabled();
48     }
49 
50     /** See {@link TelephonyManager#getSignalStrength() }. */
getSignalStrength(TelephonyManager telephonyManager)51     public static SignalStrength getSignalStrength(TelephonyManager telephonyManager) {
52         return telephonyManager.getSignalStrength();
53     }
54 
55     /** See {@link ClipboardManager#clearPrimaryClip() }. */
clearPrimaryClip(ClipboardManager clipboardManager)56     public static void clearPrimaryClip(ClipboardManager clipboardManager) {
57         clipboardManager.clearPrimaryClip();
58     }
59 
60     /** See {@link PackageManager#hasSigningCertificate(String, byte[], int) }. */
hasSigningCertificate( PackageManager pm, String packageName, byte[] certificate, int type)61     public static boolean hasSigningCertificate(
62             PackageManager pm, String packageName, byte[] certificate, int type) {
63         return pm.hasSigningCertificate(packageName, certificate, type);
64     }
65 
66     /** See {@link TextClassifier#suggestSelection() } */
suggestSelection( TextClassifier textClassifier, TextSelection.Request request)67     public static TextSelection suggestSelection(
68             TextClassifier textClassifier, TextSelection.Request request) {
69         return textClassifier.suggestSelection(request);
70     }
71 
72     /** See {@link TextSelection.Request.Builder#Builder() } */
newTextSelectionRequestBuilder( CharSequence text, int startIndex, int endIndex)73     public static TextSelection.Request.Builder newTextSelectionRequestBuilder(
74             CharSequence text, int startIndex, int endIndex) {
75         return new TextSelection.Request.Builder(text, startIndex, endIndex);
76     }
77 
78     /** See {@link TextSelection.Request.Builder#setDefaultLocales() } */
setDefaultLocales( TextSelection.Request.Builder builder, LocaleList defaultLocales)79     public static TextSelection.Request.Builder setDefaultLocales(
80             TextSelection.Request.Builder builder, LocaleList defaultLocales) {
81         return builder.setDefaultLocales(defaultLocales);
82     }
83 
84     /** See {@link TextSelection.Request.Builder#build() } */
build(TextSelection.Request.Builder builder)85     public static TextSelection.Request build(TextSelection.Request.Builder builder) {
86         return builder.build();
87     }
88 }
89