בדף הזה מוסבר איך להגדיר למשתמשים שמירה של נקודות גישה בין סשנים של נהיגה, בדומה לחוויית הנהיגה עם Wi-Fi ב-AAOS.
public class CarSettings {
...
@SystemApi
public static final class Global {
...
/**
* Enables persistent tethering when set to {@code "true"}.
*
* <p>When enabled, tethering is started when the car is started given
* that the hotspot was enabled at shutdown and all tethering sessions
* will remain on even if no devices are connected to it.
*
* <p>When disabled, hotspot will turn off automatically if no devices
* are connected and will no longer persist through drives.
*
* @hide
*/
@SystemApi
public static final String ENABLE_PERSISTENT_TETHERING =
"android.car.ENABLE_PERSISTENT_TETHERING";
}
}
כדי להפעיל את השיתוף באופן קבוע, משתמשים ב-ENABLE_PERSISTENT_TETHERING
דרך Settings API, שאפשר להשתמש בו גם לשליחת שאילתות.
הרשאות
השימוש ב-CarWifiManager API מוגבל. ההרשאה החדשה הזו נוצרה כדי להגן על הגישה.
public boolean canControlPersistApSettings() { ... }
רמות ההגנה של ההרשאה הזו הן:
הרשאה חדשה | הרשאה | רמת הגנה |
---|---|---|
כן | READ_PERSIST_TETHERING_SETTINGS |
חתימה | מסווג |
התנהגות ברירת המחדל של persist היא לא נתמכת. שכבת-על של משאבים (config_enablePersistTetheringCapabilities
) מוגדרת לחסימת האפשרות להפעיל שיתוף אינטרנט. כדי להשאיר את השיתוף בכוונה, צריך להגדיר את הערך ל-true
כדי להפעיל את התכונה בנוסף להסכמת המשתמש, כי אפליקציות מערכת אחרות עם ההרשאה WRITE_SECURE_SETTINGS
יכולות גם לשלוט בהגדרה הזו.
ה-API הבא קובע אם ההתנהגות מופעלת. צריך לשלוח קריאה ל-API הזה לפני שמבצעים שינוי ב-ENABLE_PERSISTENT_TETHERING
.
/**
* CarWifiManager provides API to allow for applications to perform Wi-Fi specific
* operations.
*
* @hide
*/
@SystemApi
public final class CarWifiManager extends CarManagerBase {
/**
* Returns {@code true} if the persist tethering settings are able to be
* changed.
*
* @hide
*/
@SystemApi
@RequiresPermission(Car.PERMISSION_READ_PERSIST_TETHERING_SETTINGS)
public boolean canControlPersistApSettings() { ... }
}