Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query the SDK version for Android devices. #2402

Merged
merged 1 commit into from
Nov 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/os/android/adb/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ func (b *binding) InstallAPK(ctx context.Context, path string, reinstall bool, g
if reinstall {
args = append(args, "-r")
}
if grantPermissions && b.Instance().GetConfiguration().GetOS().GetMajorVersion() >= 6 {
// Starting with Android 6.0, permissions are not granted by default
// during installation. Before Android 6.0, the flag did not exist.
if grantPermissions && b.Instance().GetConfiguration().GetOS().GetAPIVersion() >= 23 {
// Starting with API 23, permissions are not granted by default
// during installation. Before API 23, the flag did not exist.
args = append(args, "-g")
}
args = append(args, path)
Expand Down Expand Up @@ -145,8 +145,8 @@ func (b *binding) StartActivityForDebug(ctx context.Context, a android.ActivityA
// StartService launches the specified service action.
func (b *binding) StartService(ctx context.Context, a android.ServiceAction, extras ...android.ActionExtra) error {
cmd := "start-foreground-service"
if b.Instance().GetConfiguration().GetOS().GetMajorVersion() < 8 {
// "am start-foreground-service" was added in 8.0 (API 26).
if b.Instance().GetConfiguration().GetOS().GetAPIVersion() < 26 {
// "am start-foreground-service" was added in API 26.
cmd = "startservice"
}
args := append([]string{
Expand Down
7 changes: 7 additions & 0 deletions core/os/android/adb/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package adb
import (
"context"
"fmt"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -134,6 +135,12 @@ func newDevice(ctx context.Context, serial string, status bind.Status) (*binding
d.To.Configuration.OS = device.AndroidOS(major, minor, point)
}

// Collect the API version
if version, err := d.SystemProperty(ctx, "ro.build.version.sdk"); err == nil {
v, _ := strconv.Atoi(version)
d.To.Configuration.OS.APIVersion = int32(v)
}

if description, err := d.SystemProperty(ctx, "ro.build.description"); err == nil {
d.To.Configuration.OS.Build = strings.TrimSpace(description)
}
Expand Down
2 changes: 2 additions & 0 deletions core/os/device/device.proto
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ message OS {
int32 minor_version = 5;
// The point version of the OS.
int32 point_version = 6;
// The API version of the OS.
int32 API_version = 7;
}

// CPU represents a specific central processing unit product.
Expand Down