Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 153fb1c6 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge changes I9de0ffe9,Idc804896

* changes:
  Use sdkparcelables to generate framework.aidl
  Initial sdkparcelables
parents f2ebbd13 77ebd08d
Loading
Loading
Loading
Loading
+19 −14
Original line number Diff line number Diff line
@@ -248,12 +248,26 @@ aidl_files := \
	system/netd/server/binder/android/net/UidRange.aidl \
	frameworks/base/telephony/java/android/telephony/PcoData.aidl \

aidl_parcelables :=
define stubs-to-aidl-parcelables
  gen := $(TARGET_OUT_COMMON_INTERMEDIATES)/$1.aidl
  aidl_parcelables += $$(gen)
  $$(gen): $(call java-lib-header-files,$1) | $(HOST_OUT_EXECUTABLES)/sdkparcelables
	@echo Extract SDK parcelables: $$@
	rm -f $$@
	$(HOST_OUT_EXECUTABLES)/sdkparcelables $$< $$@
endef

$(foreach stubs,android_stubs_current android_test_stubs_current android_system_stubs_current,\
  $(eval $(call stubs-to-aidl-parcelables,$(stubs))))

gen := $(TARGET_OUT_COMMON_INTERMEDIATES)/framework.aidl
$(gen): PRIVATE_SRC_FILES := $(aidl_files)
ALL_SDK_FILES += $(gen)
$(gen): $(aidl_files) | $(AIDL)
		@echo Aidl Preprocess: $@
		$(hide) $(AIDL) --preprocess $@ $(PRIVATE_SRC_FILES)
.KATI_RESTAT: $(gen)
$(gen): $(aidl_parcelables)
	@echo Combining SDK parcelables: $@
	rm -f $@.tmp
	cat $^ | sort -u > $@.tmp
	$(call commit-change-for-toc,$@)

# the documentation
# ============================================================
@@ -491,8 +505,6 @@ LOCAL_UNINSTALLABLE_MODULE := true

include $(BUILD_DROIDDOC)

# $(gen), i.e. framework.aidl, is also needed while building against the current stub.
$(full_target): $(gen)
$(INTERNAL_PLATFORM_API_FILE): $(full_target)
$(call dist-for-goals,sdk,$(INTERNAL_PLATFORM_API_FILE))

@@ -528,8 +540,6 @@ LOCAL_UNINSTALLABLE_MODULE := true

include $(BUILD_DROIDDOC)

# $(gen), i.e. framework.aidl, is also needed while building against the current stub.
$(full_target): $(gen)
$(INTERNAL_PLATFORM_SYSTEM_API_FILE): $(full_target)
$(call dist-for-goals,sdk,$(INTERNAL_PLATFORM_SYSTEM_API_FILE))

@@ -566,8 +576,6 @@ LOCAL_UNINSTALLABLE_MODULE := true

include $(BUILD_DROIDDOC)

# $(gen), i.e. framework.aidl, is also needed while building against the current stub.
$(full_target): $(gen)
$(INTERNAL_PLATFORM_TEST_API_FILE): $(full_target)
$(call dist-for-goals,sdk,$(INTERNAL_PLATFORM_TEST_API_FILE))

@@ -597,9 +605,6 @@ LOCAL_UNINSTALLABLE_MODULE := true

include $(BUILD_DROIDDOC)

# $(gen), i.e. framework.aidl, is also needed while building against the current stub.
$(full_target): $(gen)

# Run this for checkbuild
checkbuild: doc-comment-check-docs
# Check comment when you are updating the API
+22 −0
Original line number Diff line number Diff line
java_binary_host {
    name: "sdkparcelables",
    manifest: "manifest.txt",
    srcs: [
        "src/**/*.kt",
    ],
    static_libs: [
        "asm-6.0",
    ],
}

java_library_host {
    name: "sdkparcelables_test",
    manifest: "manifest.txt",
    srcs: [
        "tests/**/*.kt",
    ],
    static_libs: [
        "sdkparcelables",
        "junit",
    ],
}
+1 −0
Original line number Diff line number Diff line
Main-class: com.android.sdkparcelables.MainKt
+28 −0
Original line number Diff line number Diff line
package com.android.sdkparcelables

import org.objectweb.asm.ClassVisitor
import java.util.*

data class Ancestors(val superName: String?, val interfaces: List<String>?)

/** A class that implements an ASM ClassVisitor that collects super class and
 * implemented interfaces for each class that it visits.
 */
class AncestorCollector(api: Int, dest: ClassVisitor?) : ClassVisitor(api, dest) {
    private val _ancestors = LinkedHashMap<String, Ancestors>()

    val ancestors: Map<String, Ancestors>
        get() = _ancestors

    override fun visit(version: Int, access: Int, name: String?, signature: String?,
                       superName: String?, interfaces: Array<out String>?) {
        name!!

        val old = _ancestors.put(name, Ancestors(superName, interfaces?.toList()))
        if (old != null) {
            throw RuntimeException("class $name already found")
        }

        super.visit(version, access, name, signature, superName, interfaces)
    }
}
 No newline at end of file
+56 −0
Original line number Diff line number Diff line
package com.android.sdkparcelables

import org.objectweb.asm.ClassReader
import org.objectweb.asm.Opcodes
import java.io.File
import java.io.IOException
import java.util.zip.ZipFile

fun main(args: Array<String>) {
    if (args.size != 2) {
        usage()
    }

    val zipFileName = args[0]
    val aidlFileName = args[1]

    val zipFile: ZipFile

    try {
        zipFile = ZipFile(zipFileName)
    } catch (e: IOException) {
        System.err.println("error reading input jar: ${e.message}")
        kotlin.system.exitProcess(2)
    }

    val ancestorCollector = AncestorCollector(Opcodes.ASM6, null)

    for (entry in zipFile.entries()) {
        if (entry.name.endsWith(".class")) {
            val reader = ClassReader(zipFile.getInputStream(entry))
            reader.accept(ancestorCollector,
                    ClassReader.SKIP_CODE or ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES)
        }
    }

    val parcelables = ParcelableDetector.ancestorsToParcelables(ancestorCollector.ancestors)

    try {
        val outFile = File(aidlFileName)
        val outWriter = outFile.bufferedWriter()
        for (parcelable in parcelables) {
            outWriter.write("parcelable ")
            outWriter.write(parcelable.replace('/', '.').replace('$', '.'))
            outWriter.write(";\n")
        }
        outWriter.flush()
    } catch (e: IOException) {
        System.err.println("error writing output aidl: ${e.message}")
        kotlin.system.exitProcess(2)
    }
}

fun usage() {
    System.err.println("Usage: <input jar> <output aidl>")
    kotlin.system.exitProcess(1)
}
 No newline at end of file
Loading