Set up framework and service for Nearby module.

Files under framework/api are updated using
`build/soong/scripts/gen-java-current-api-files.sh
"packages/modules/Nearby/framework/api"  system- module-lib- && m
update-api`. They are essentially empty as nearby platform APIs do not
exist yet.

Bug: 189355156
Test: mmm -j packages/modules/Nearby
Change-Id: I8df0e459a962b54cbd1a891f1fe2a1474f4cbc75
diff --git a/nearby/README.md b/nearby/README.md
index 7c69b9e..120de1d 100644
--- a/nearby/README.md
+++ b/nearby/README.md
@@ -28,4 +28,12 @@
 $ cd packages/modules/Nearby
 $ aidegen
 # This will launch Intellij project for Nearby module.
+```
+
+## Build and Install
+
+```sh
+$ source build/envsetup.sh && lunch <TARGE>
+$mmm -j packages/modules/Nearby/
+$adb install -r {ANDROID_PRODUCT_OUT}/system/apex/com.android.nearby.apex
 ```
\ No newline at end of file
diff --git a/nearby/apex/com.android.nearby/Android.bp b/nearby/apex/com.android.nearby/Android.bp
index 9aee502..3df7f08 100644
--- a/nearby/apex/com.android.nearby/Android.bp
+++ b/nearby/apex/com.android.nearby/Android.bp
@@ -26,7 +26,28 @@
     name: "com.android.nearby",
     manifest: "manifest.json",
     // TODO(b/189890387): change the SDK version to T when T release is available.
-    min_sdk_version: "S",
+    min_sdk_version: "current",
+    updatable: true,
     file_contexts: ":apex.test-file_contexts",  // Default, please edit, see go/android-apex-howto
     key: "com.android.nearby.key",
+    certificate: ":com.android.nearby.certificate",
+
+    bootclasspath_fragments: ["com.android.nearby-bootclasspath-fragment"],
+    java_libs: [
+        "service-nearby",
+    ],
+}
+
+sdk {
+    name: "nearby-module-sdk",
+    java_sdk_libs: [
+        "framework-nearby",
+    ],
+}
+
+// Encapsulate the contributions made by the com.android.nearby to the bootclasspath.
+bootclasspath_fragment {
+    name: "com.android.nearby-bootclasspath-fragment",
+    contents: ["framework-nearby"],
+    apex_available: ["com.android.nearby"],
 }
diff --git a/nearby/framework/Android.bp b/nearby/framework/Android.bp
new file mode 100644
index 0000000..5339551
--- /dev/null
+++ b/nearby/framework/Android.bp
@@ -0,0 +1,84 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+filegroup {
+    name: "nearby-java-sources",
+    srcs: [
+        "java/**/*.java",
+        "java/**/*.aidl",
+    ],
+    path: "java",
+    visibility: ["//visibility:private"],
+}
+
+// Defaults shared between `framework-nearby` & `framework-nearby-pre-jarjar`
+java_defaults {
+    name: "framework-nearby-defaults",
+    defaults: ["nearby-module-sdk-version-defaults"],
+    srcs: [
+        ":nearby-java-sources",
+    ],
+}
+
+// Defaults for SDK versions.
+java_defaults {
+    name: "nearby-module-sdk-version-defaults",
+    min_sdk_version: "current",
+    target_sdk_version: "current",
+}
+
+
+// Nearby-service needs pre-jarjared version of framework-nearby so it can reference copied utility
+// classes before they are renamed.
+java_library {
+    name: "framework-nearby-pre-jarjar",
+    defaults: ["framework-nearby-defaults"],
+    sdk_version: "module_current",
+    libs: ["framework-annotations-lib"],
+    // java_api_finder must accompany `srcs` (`srcs` defined in `framework-nearby-defaults`)
+    plugins: ["java_api_finder"],
+    installable: false,
+    visibility: [
+        "//packages/modules/Nearby/service",
+    ],
+}
+
+// SDK library for nearby module API.
+java_sdk_library {
+    name: "framework-nearby",
+    defaults: [
+        "framework-module-defaults",  // the SDK needs to be usable in all processes
+        "framework-nearby-defaults",
+    ],
+
+    apex_available: [
+        "com.android.nearby",
+    ],
+    installable: true,
+    optimize: {
+        enabled: false
+    },
+
+    // Restrict access to implementation library.
+    impl_library_visibility: [
+        "//packages/modules/Nearby/service:__subpackages__",
+    ],
+    permitted_packages: [
+        "android.nearby",
+    ],
+}
diff --git a/nearby/framework/api/current.txt b/nearby/framework/api/current.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/nearby/framework/api/current.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/nearby/framework/api/module-lib-current.txt b/nearby/framework/api/module-lib-current.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/nearby/framework/api/module-lib-current.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/nearby/framework/api/module-lib-removed.txt b/nearby/framework/api/module-lib-removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/nearby/framework/api/module-lib-removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/nearby/framework/api/removed.txt b/nearby/framework/api/removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/nearby/framework/api/removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/nearby/framework/api/system-current.txt b/nearby/framework/api/system-current.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/nearby/framework/api/system-current.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/nearby/framework/api/system-removed.txt b/nearby/framework/api/system-removed.txt
new file mode 100644
index 0000000..d802177
--- /dev/null
+++ b/nearby/framework/api/system-removed.txt
@@ -0,0 +1 @@
+// Signature format: 2.0
diff --git a/nearby/framework/api/test-current.txt b/nearby/framework/api/test-current.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/nearby/framework/api/test-current.txt
diff --git a/nearby/framework/api/test-removed.txt b/nearby/framework/api/test-removed.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/nearby/framework/api/test-removed.txt
diff --git a/nearby/framework/java/android/nearby/INearbyManager.aidl b/nearby/framework/java/android/nearby/INearbyManager.aidl
new file mode 100644
index 0000000..031c31d
--- /dev/null
+++ b/nearby/framework/java/android/nearby/INearbyManager.aidl
@@ -0,0 +1,23 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package android.nearby;
+
+/**
+ * Interface for communicating with the nearby services.
+ *
+ * @hide
+ */
+interface INearbyManager {
+}
\ No newline at end of file
diff --git a/nearby/framework/java/android/nearby/NearbyManager.java b/nearby/framework/java/android/nearby/NearbyManager.java
new file mode 100644
index 0000000..b75e640
--- /dev/null
+++ b/nearby/framework/java/android/nearby/NearbyManager.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.nearby;
+
+/**
+ * This class provides a way to perform Nearby related operations such as scanning and connecting
+ * to nearby devices.
+ *
+ * <p> To get a {@link NearbyManager} instance, call the
+ * <code>Context.getSystemService(NearbyManager.class)</code>.
+ *
+ * @hide
+ */
+// TODO(b/189954300): implement NearyManager API and unhide it.
+public class NearbyManager {
+}
diff --git a/nearby/service/Android.bp b/nearby/service/Android.bp
new file mode 100644
index 0000000..5b026fa
--- /dev/null
+++ b/nearby/service/Android.bp
@@ -0,0 +1,57 @@
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+    default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+filegroup {
+    name: "nearby-service-srcs",
+    srcs: [
+        "java/**/*.java",
+    ],
+}
+
+// Main lib for nearby services.
+java_library {
+    name: "service-nearby",
+    srcs: [":nearby-service-srcs"],
+
+    defaults: [
+        "nearby-module-sdk-version-defaults",
+        "framework-system-server-module-defaults"
+    ],
+    libs: [
+        // pre-jarjar symbols are needed so that nearby-service can reference the original class
+        // names at compile time
+        "framework-nearby-pre-jarjar",
+    ],
+    sdk_version: "system_server_current",
+
+    installable: true,
+    optimize: {
+        enabled: true,
+        shrink: true,
+    },
+    dex_preopt: {
+        enabled: false,
+        app_image: false,
+    },
+    visibility: [
+        "//packages/modules/Nearby/apex",
+    ],
+    apex_available: [
+        "com.android.nearby",
+    ],
+}
\ No newline at end of file
diff --git a/nearby/service/java/com/android/server/nearby/NearbyService.java b/nearby/service/java/com/android/server/nearby/NearbyService.java
new file mode 100644
index 0000000..5647a4d
--- /dev/null
+++ b/nearby/service/java/com/android/server/nearby/NearbyService.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.nearby;
+
+import android.content.Context;
+
+import com.android.server.SystemService;
+
+/**
+ * Service implementing nearby functionality. The actual implementation is delegated to
+ * {@link NearbyDeviceScanServiceImpl}.
+ */
+// TODO(189954300): Implement nearby service.
+public class NearbyService extends SystemService {
+    private final NearbyServiceImpl mImpl;
+
+    public NearbyService(Context contextBase) {
+        super(contextBase);
+        mImpl = new NearbyServiceImpl(contextBase);
+    }
+
+    @Override
+    public void onStart() {
+    }
+
+    @Override
+    public void onBootPhase(int phase) {
+    }
+}
diff --git a/nearby/service/java/com/android/server/nearby/NearbyServiceImpl.java b/nearby/service/java/com/android/server/nearby/NearbyServiceImpl.java
new file mode 100644
index 0000000..959d12d
--- /dev/null
+++ b/nearby/service/java/com/android/server/nearby/NearbyServiceImpl.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.nearby;
+
+import android.content.Context;
+import android.nearby.INearbyManager;
+
+/**
+ * Implementation of {@link NearbyService}.
+ */
+public class NearbyServiceImpl extends INearbyManager.Stub {
+
+    public NearbyServiceImpl(Context context) {
+    }
+}